You are on page 1of 7

OSS 4006 A

Image processing

Austin Miller

October 18th, 2023

% Exercise 1: This
f=imread('C:\Users\austi_\Downloads\liver-cells-gray.jpg');
h=imhist(f,20);
horz=linspace(0,255,20);
stem(horz,h,'filled','LineWidth',0.5)
ax=gca;
ax.Color=[179,207,227]/255;

Figure 1. Histogram from exercise 1


Exercise 1 creates a histogram of the image “liver-cells-gray.jpg” for the intensities
between 0 and 255.

d.

% Exercise 1 d
f=imread('C:\Users\austi_\Downloads\liver-cells-gray.jpg');
hp=imhist(f);
plot(hp,'Color',[112 28 25]/255,'LineWidth',1.0)
ax=gca;
ax.Color=[228,221,218]/255;
ax.FontName='Times Ten'
ax.FontSize=8;

Figure 2. An image of the histogram that uses a plot function, instead of a linspace

This function creates a histogram that is more continuous since it uses the plot
function.

Exercise 2

f=imread('C:\Users\austi_\Downloads\phoenix-lander.tif');
figure,imshow(f);
g=histeq(f);
figure,imshow(g);
figure,imhist(f);
figure,imhist(g);

Figure 3. (Left) image f and Figure 4. (Right) Image g

The greyscale transformation applied transforms the grayscale image f so that the
histogram of the output grayscale image g has 64 bins and is approximately flat.

The normal and equalized histograms of the image in Figure 5. (Left) and Figure 6.
(Right) respectively
f=imread('C:\Users\austi_\Downloads\phoenix-lander.tif');
hnorm=imhist(f)/numel(f); %Normalized histogram.
cdf=cumsum(hnorm);
r=linspace(0,1,256); % 256 values in the range [0,1]
figure, plot(r,cdf)

Figure 7. The normalized histogram of the image f

The normalized histogram is a cumulative sum of the probability distribution of the


intensity values of the image f. This means that as the intensity increases, the
probability is less that it appears in the average pixel.

Exercise 3.

f = imread('C:\Users\austi_\Downloads\spillway-dark.tif');

% Exercise 1 - part b)
g = intXform4e(f, "log", 3);
figure, imshow(g)

% Exercise 1 - part c)
g = intXform4e(f, "gamma", 0.5);
figure, imshow(g)

function [g, map] = intXform4e(f, mode, param)


if isfloat(f) && (max(f(:)) > 1 || min(f(:)) < 0)
f = mat2gray(f);
end

f = im2double(f);

switch mode
case 'neg'
g = imcomplement(1 - f);
case 'gamma'
g = gammaTransform(f, param);
case 'log'
g = log(1 + f);
otherwise
error('Unknown enhancement method.')
end
end

% The function for gamma transformation used by intXform4e


function g = gammaTransform(f, gamma)
g = f.^gamma;
end
b)

Figure 8. Logarithm transform applied

The logarithm transformed image becomes slightly darker because the logarithm makes
the dark pixels more pronounced.
c)

Figure 9. The gamma transform applied to the image.

The image has been transformed using a gamma value, which exponentially increased the
intensity values of the image, making the brighter spots brighter.

d) The image can be improved by changing the gamma value, of which the optimized
values can be found by changing the gamma lower to make the image brighter and higher
to make the image darker.

You might also like