I am doing an image enhancement technique which enhances dim lit images. I have divided a 640 x 480 image into blocks of 16 images of size 160 x 120 and doing enhancement on each block separately depending on the brightness of each block and then join all these blocks back to form the final image.
The final output image will look like 16 subimages with different contrast and hence blocky in appearance. I assume bilinear interpolation should fix this issue. Could any one please tell me on how to do the interpolation on this image and fix it. I was doing the coding in matlab and opencv so any codes are also welcome.
The program checks the overall brightness of the image and enhances it accordingly. If the image is taken in a bright environment ,the enhancement would be minimal whereas, if the image is dark , more enhancement would be done.
On how the program checks if the image is bright or not is done accordingly. The image is divided into quarters and sixteenths and a reference of 9 pixels are selected. Summing the luminance values of these pixels gives an over all brightness of the image. Lower values for the sum indicates a dark image and vice versa.
I divided the image so that in presence of a bright light in a dark environment, the area around the bright light gets minimal or no enhancement while the dark regions are enhanced more. Thus the final output is sub images wit different c开发者_运维百科ontrasts.
I think interpolation would smooth out the edges that are formed in between two sub images. Would there be any other way to fix the final image so that it looks smoother?
Hope the above explanation makes it a bit more clear. The code given below is a coarse code and not the actual code i am using. The code just shows how the method works and output image looks after the enhancement is done.
f=imread('3.jpg');
f=imresize(f,[480 640]);
figure(1);image(f);
f=rgb2ycbcr(f);
a=1;b=1;q=0;
f1=f(:,:,1);
for r=1:4
for c=1:4
sumterm = uint16(f1(30*r,40*c))+uint16(f1(30*r,80*c))+uint16(f1(30*r,120*c))+uint16(f1(60*r,40*c))+uint16(f1(60*r,80*c))+uint16(f1(60*r,120*c))+uint16(f1(90*r,40*c))+uint16(f1(90*r,80*c))+uint16(f1(90*r,120*c));
q=q+1;
for i=a:a+119
for j=b:b+159
if sumterm >=0 && sumterm <= 113
f1(i,j) =f1(i,j)*5;
elseif sumterm > 113 && sumterm <=226
f1(i,j) =f1(i,j)*5;
elseif sumterm >226 && sumterm <=339
f1(i,j) =f1(i,j)*4;
elseif sumterm >339 && sumterm <=452
f1(i,j) =f1(i,j)*3;
elseif sumterm >452 && sumterm <=565
f1(i,j) =f1(i,j)*2;
elseif sumterm >565 && sumterm <=678
f1(i,j) =f1(i,j)*1.8;
elseif sumterm >678 && sumterm <=791
f1(i,j) =f1(i,j)*1.6;
elseif sumterm >791 && sumterm <=904
f1(i,j) =f1(i,j)*1.4;
elseif sumterm >904 && sumterm <=1020
f1(i,j) =f1(i,j)*1.2;
else
f1(i,j) =f1(i,j)*1;
end
end
end
if(b<640-160)
b=j+1;
end
end
a=i+1;
b=1;
end
f(:,:,1)=f1;
f=ycbcr2rgb(f);
image(f);
Have you considered a histogram equalization contrast stretch?
Since we're talking about smoothing, a median filter could be your best bet. Have a look at its output in Wikipedia. Also, check out Gaussian Blur.
精彩评论