A low contrast image with brightenss values in a narrow rang

A low contrast image with brightenss values in a narrow range [a,b] needs to be expanded to cover a larger range [c,d] to increase its contrast. Write pseudo-code to implement a pixel-wise operator to transform brightness at each pixel so that the contrast is enhanced.

Solution

Function below will clamp all values to fall within
range[c,d] (enhanced range)
public void run(ImageProcessor ip)
{
int w=ip.getWidth();
int h=ip.getHeight();
  
for(int v=0;v<h;v++)
{
for(int u=0;u<w;u++)
   {
   int c=(int) (ip.get(u,v)*1.5+0.5);// Increase contrast by 50%
   if(c>255)
   c=255; //clamp to max. value
   ip.set(u,v,c);
   }
   }
}
      

A low contrast image with brightenss values in a narrow range [a,b] needs to be expanded to cover a larger range [c,d] to increase its contrast. Write pseudo-co

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site