1- Upload an image into Matlab. 2- Find the histogram of that image. 3- For each
ID: 671009 • Letter: 1
Question
1- Upload an image into Matlab.
2- Find the histogram of that image.
3- For each pixel value between 0 and 255, find the membership of that value in the different input memberships, and use the defuzzification equation in slide 2 to find out what will that pixel value be mapped to, this will create your Look up table or mapping function.
4- Here you have to do two different things and compare them:
a- You either apply the mapping function directly on every pixel in the image.
b- Or apply the mapping function on the image histogram and use histogram matching to try to match the image histogram to the new mapped histogram.
5- In either cases you need to show me the output image and its histogram and comment on the results.
6- Repeat steps using different values until you are satisfied qualitatively with your results
Explanation / Answer
-ImageAnalyst
>
> % function double_image_histogram()
>
> % Change the current folder to the folder of this m-file.
> % (The line of code below is from Brett Shoelson of The Mathworks.)
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
> clc; % Clear command window.
> clear; % Delete all variables.
> close all; % Close all figure windows except those created by imtool.
> imtool close all; % Close all figure windows created by imtool.
> workspace; % Make sure the workspace panel is showing.
> fontSize = 20;
>
> % Read in standard MATLAB gray scale demo image.
> grayImage = imread('cameraman.tif');
> subplot(2, 2, 1);
> imshow(grayImage, []);
> title('Original Grayscale Image', 'FontSize', fontSize);
> set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
>
> % Let's get its histogram.
> [pixelCount grayLevels] = imhist(grayImage);
> subplot(2, 2, 3);
> bar(pixelCount);
> xlim([0 grayLevels(end)]); % Scale x axis manually.
> title('Original Grayscale Histogram', 'FontSize', fontSize);
>
> % Now let's synthesize an image that is a floating point
> % image and has values from -12345 to +54321.
> originalMinValue = double(min(min(grayImage)))
> originalMaxValue = double(max(max(grayImage)))
> originalRange = originalMaxValue - originalMinValue;
>
> % Get a double image in the range -127 to +128
> desiredMin = -45678;
> desiredMax = 54321;
> desiredRange = desiredMax - desiredMin;
> dblImageS = desiredRange * (double(grayImage) - originalMinValue) /
> originalRange + desiredMin;
>
> % So now we have a double image that is our "starting image."
> % However can't use imhist on this. We need to scale to 0-1.
> minValueS = min(min(dblImageS))
> maxValueS = max(max(dblImageS))
> rangeS = maxValueS - minValueS;
> dblImage = (dblImageS - minValueS) / rangeS;
> % Check to verify that range is now 0-1.
> minValueNorm = min(min(dblImage))
> maxValueNorm = max(max(dblImage))
> subplot(2, 2, 2);
> imshow(dblImage, []);
> title('Double Image', 'FontSize', fontSize);
>
> % Let's get its histogram into 256 bins.
> [pixelCountD grayLevelsD] = imhist(dblImage, 256);
> % But now grayLevelsD goes from 0 to 1.
> % We want it to go from the original range, so we need to scale.
> originalDoubleGrayLevels = rangeS * grayLevelsD + minValueS;
>
> subplot(2, 2, 4);
> plot(originalDoubleGrayLevels, pixelCountD);
> title('Histogram of double image', 'FontSize', fontSize);
> % Scale x axis manually.
> xlim([originalDoubleGrayLevels(1) originalDoubleGrayLevels(end)]);
>
>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.