Why getting black image as output?

6 次查看(过去 30 天)
I am writing a script for histogram equalisation and I came up with the following,
org_image = imread('image.jpg')
tot_pixel = size(org_image,1) * size(org_image,2)
%working on each plane separately
R = org_image(:,:,1);
%finding intensity frequencies in each plane
[R_freq,R_intensity] = imhist(R);
%finding intensity probability in each plane
R_prob = R_freq/tot_pixel;
%finding the cummulative histogram of each pixel
R_cumm = R_prob;
for i=2 : 256
R_cumm(i)=R_cumm(i-1)+R_prob(i);
end
%finding cumulative distribution probability of each pixel
R_cumm_prob = R_cumm / tot_pixel;
%finding final value of each pixel
R_final = round(R_cumm_prob * 255);
R_equi_image = uint8(zeros(size(org_image,1), size(org_image,2)));
for i=1:size(org_image,1)
for j=1:size(org_image,2)
R_equi_image(i,j)=R_final(org_image(i,j));
end
end
equi_image = uint8(zeros(size(org_image,1), size(org_image,2)));
equi_image = cat(3,R_equi_image,G_equi_image,B_equi_image);
figure, imshow(org_image);
figure, imshow(equi_image);
Where am I going wrong?
  4 个评论
Mohana Singh
Mohana Singh 2018-9-7
编辑:Mohana Singh 2018-9-8
Ah, I was normalising it twice. Removing the 'cumulative distribution probability' step gives better results.
Image Analyst
Image Analyst 2018-9-7
Nothing will give good results because histogram equalization is a bad algorithm. Even worse for you because you're using the crudest, most primitive version of it. Histogram equalization gives harsh, bad looking, unnatural images, even if you were to use a more sophisticated algorithm (of which I have several). I recommend you don't even do it. By the way, did you see my Answer below?

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2018-9-7
You can use intlut() to map pixels into other values. See the histogram processing fun demo in my File Exchange: https://www.mathworks.com/matlabcentral/fileexchange/28972-custom-shaped-histogram
This script transforms an image such that the object in the "foreground" of the image now becomes the histogram of the transformed image. I provide three examples with 3 demo images: I change the image of a city skyline so that the histogram of the new image looks like the skyline. I change the image of a car so that the histogram of the new image looks like the car shape. I change the image of a woman so that the histogram of the new image looks like the shape of the woman. (See screenshot) The script can also produce a perfectly flat histogram - the ultimate histogram equalization, far better than any standard histogram equalization method because the final histogram is TRULY FLAT.
In addition I give some examples for how to segment multi-colored objects (car, skyline, woman) out of the foreground of the image, thus demonstrating some standard image processing techniques such as color classification and thresholding.
As an extra bonus, I provide a thresholding GUI application where you can interactively threshold your image with scrollbars and see the results (original, binary, and masked) immediately. You can use this with any integer or floating point image. Here, if you uncomment it in the code, you can use it to select threshold values for the hue, saturation, and value channels of the "beach_woman" image. But it can be used in general for any image - it's not specific for this shaped histogram script, it's just bundled in.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by