You are on page 1of 2

>> grayImage = imread('f16.gif'); % Get the dimensions of the image. % numberOfColorBands should be = 1.

[rows, columns, numberOfColorBands] = size(grayImage); if numberOfColorBands > 1 % It's not really gray scale like we expected - it's color. % Convert it to gray scale by taking only the green channel. grayImage = grayImage(:, :, 2); % Take green channel. end % Display the original gray scale image. subplot(2, 2, 1); imshow(grayImage, []); title('Original Grayscale Image'); % Enlarge figure to full screen. set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Give a name to the title bar. set(gcf,'name','Bi-Histogram Equalization','numbertitle','off') % Calculate mean gray level. meanGL = mean2(grayImage) % Let's compute and display the histogram. [pixelCount, grayLevels] = imhist(grayImage); subplot(2, 2, 2); bar(pixelCount); grid on; title('Histogram of original image'); xlim([0 grayLevels(end)]); % Scale x axis manually. % Put line at mean yl = ylim; line([meanGL, meanGL], [yl(1), yl(2)], 'LineWidth', 2, 'Color', 'r'); binaryImageLow = grayImage < meanGL; binaryImageHigh = grayImage >= meanGL; % Display the image. subplot(2, 2, 3); imshow(binaryImageLow, []); title('Binary Image Below Mean'); % Display the image. subplot(2, 2, 4); imshow(binaryImageHigh, []); title('Binary Image Above Mean'); % Get maps for each [TEMP17393, lowMap] = histeq(grayImage(binaryImageLow)); [TEMP17394, highMap] = histeq(grayImage(binaryImageHigh)); % Combine them. intMeanGL = int32(meanGL); lookupTable = uint8(256*[lowMap(1:intMeanGL), highMap(intMeanGL+1:end)]); % Use lookup table to map image. % KEY PART RIGHT HERE!!! BiHistEqImage = intlut(grayImage, lookupTable); % Display the image. figure; subplot(2, 2, 1); imshow(BiHistEqImage, []); % Let's compute and display the histogram. [pixelCount, grayLevels] = imhist(BiHistEqImage); subplot(2, 2, 2); bar(pixelCount); grid on; title('Histogram of BiHistEqImage image'); xlim([0 grayLevels(end)]); % Scale x axis manually. % Put line at mean

y2 = ylim; line([mean2(BiHistEqImage), mean2(BiHistEqImage)], [y2(1), y2(2)], 'LineWidth', 2, 'Color', 'r'); orghiseq =histeq(grayImage); subplot(2, 2, 3); imshow(orghiseq, []); % Let's compute and display the histogram. [pixelCount, grayLevels] = imhist(orghiseq); subplot(2, 2, 4); bar(pixelCount); grid on; title('Histogram of orghistEQ image'); xlim([0 grayLevels(end)]); % Scale x axis manually. line([mean2(orghiseq), mean2(orghiseq)], [y2(1), y2(2)], 'LineWidth', 2, 'Color' , 'r');

You might also like