|
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e019a063-585a-4206-af29-f78e3b3c70c3@o30g2000vbc.googlegroups.com>...
> On Jun 7, 4:28?am, "Matman86 Di"
> You can invert the equalization only if you keep everything floating
> point. If you quantize through use of histogram, then sometimes two
> bins get combined into one bin. To split that one bin up into two
> bins again is impossible because you don't know the relative
> porportion of the two bins that went into the one bin, unless you kept
> the original histogram. (But if you kept that then why don't you just
> keep the original image also?)
>
> You can get somewhat close except for the bins that got combined will
> not get split up. The following code illustrates this perfectly:
> % Demo macro to ...
> % by ImageAnalyst
> clc;
> close all;
> originalImage = imread('cameraman.tif');
> [rows columns numberOfColorBands] = size(originalImage);
> subplot(3, 3, 1);
> imshow(originalImage, []);
> title('Histogram');
>
> [pixelCounts grayLevels] = imhist(originalImage);
> subplot(3,3,2);
> bar(pixelCounts);
> title('Histogram');
>
> cdf = uint8(255 * cumsum(pixelCounts) / (double(rows) * double
> (columns)));
> subplot(3,3,3);
> plot(cdf);
> title('CDF');
>
> equalizedimage = intlut(originalImage, cdf); % equalization
> subplot(3,3,4);
> imshow(equalizedimage, []);
> title('Equalized Image');
>
> [pixelCountsEq grayLevelsEq] = imhist(equalizedimage);
> subplot(3,3,5);
> bar(pixelCountsEq);
> title('Equalized Histogram');
>
> cdfEq = uint8(255 * cumsum(pixelCountsEq) / (double(rows) * double
> (columns)));
> subplot(3,3,6);
> plot(cdfEq);
> title('Equalized CDF');
>
> % Invert the cdf
> inverseCDF2 = -50 *ones(256,1);
> inverseindexes = 1:256;
> for gl = 0:255
> outputGL = cdf(gl+1);
> inverseCDF2(outputGL + 1) = gl;
> end
> missing = inverseCDF2 < 0;
> inverseCDF2(missing) = [];
> inverseindexes(missing) = [];
> % Fill in missing points
> inverseCDF = uint8(interp1(inverseindexes, inverseCDF2, 1:256));
> inverseCDF(256) = inverseCDF(255);
> subplot(3,3,7);
> plot(inverseCDF);
> title('Inverse CDF');
>
> % Tranform equalized image with the inverse transform.
> restoredimage = intlut(equalizedimage, inverseCDF); % equalization
> subplot(3,3,8);
> imshow(restoredimage, []);
> title('Equalized Image');
>
> % See how it looks - it's histogram should be similar to the original
> % but not exact.
> [pixelCountsR grayLevelsR] = imhist(restoredimage);
> subplot(3,3,9);
> bar(pixelCountsR);
> title('Restored Histogram');
>
> set(gcf, 'Position', get(0, 'ScreenSize'));
>
>
> Note from the plots that the input range of 25-100 got mapped into
> about 50-75 (75 bins got squished into only 25 bins). Now those 25
> bins need to get expanded out into 75 bins again but you can't. It
> just spaces out the 25 bins (see the gaps in the final restored
> histogram). So the final restored histogram looks similar to the
> original histogram but is not exact due to gaps in it.
>
> Hope this helps explain things a bit.
> Good luck,
> ImageAnalyst
You were very nice,thanks much for help and patiente:D
|