Why getting black image as output?

1 visualización (últimos 30 días)
Mohana Singh
Mohana Singh el 7 de Sept. de 2018
Editada: Mohana Singh el 8 de Sept. de 2018
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 comentarios
Mohana Singh
Mohana Singh el 7 de Sept. de 2018
Editada: Mohana Singh el 8 de Sept. de 2018
Ah, I was normalising it twice. Removing the 'cumulative distribution probability' step gives better results.
Image Analyst
Image Analyst el 7 de Sept. de 2018
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?

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 7 de Sept. de 2018
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.

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by