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 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](/WebImages/22/a-low-contrast-image-with-brightenss-values-in-a-narrow-rang-1052626-1761548606-0.webp)
