0% found this document useful (0 votes)
63 views

TEL 432 E: Digital Image Processing

The document discusses two digital image processing techniques: 1. Histogram equalization, which stretches pixel values that occur frequently and compresses values that occur infrequently, resulting in a flatter histogram for the output image. Matlab code for histogram equalization is provided. 2. Histogram matching, which allows specifying which pixel values to emphasize or de-emphasize by matching the histogram of the input image to a desired histogram. Matlab code for histogram matching is also given. Sample input and output images are shown along with histograms and the transfer function plots.

Uploaded by

Saurav Raj
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

TEL 432 E: Digital Image Processing

The document discusses two digital image processing techniques: 1. Histogram equalization, which stretches pixel values that occur frequently and compresses values that occur infrequently, resulting in a flatter histogram for the output image. Matlab code for histogram equalization is provided. 2. Histogram matching, which allows specifying which pixel values to emphasize or de-emphasize by matching the histogram of the input image to a desired histogram. Matlab code for histogram matching is also given. Sample input and output images are shown along with histograms and the transfer function plots.

Uploaded by

Saurav Raj
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

stanbul Teknik niversitesi

Elektrik Elektronik Fakltesi Telekomnikasyon Mhendislii Blm

TEL 432 E

DIGITAL IMAGE PROCESSING

-Homework 2-

Batuhan Osmanoglu 040010250

Image Enhancement Histogram Equalization & Matching

Histogram equalization is used to equally distribute the number of pixels between grey levels. It stretches or compresses the image such that (A: input image, B:output image): Pixel values that occur frequently in A occupy a bigger dynamic range in B, i.e., get stretched and become more visible. Pixel values that occur infrequently in A occupy a smaller dynamic range in B, i.e., get compressed and become less visible.

Histogram equalization is not ideal, i.e., in general B will have aflatter histogram than A, but pB(l) is not guaranteed to be uniform (flat). (Cited from Lecture notes of Onur G. Guleryuz, Dept. of ECE, Polytechnic Univ., Brooklyn, NY) Histogram Matching allow us to specify which pixel values we want to express or depress, in other words it lets us to choose any histogram shape. Histogram Equalization This code is used for histogram equalization. MatLab Code clc; clear all; colormap('gray'); L=256; x0=imread('6010d.tif'); x0=double(x0); %input image [m,n]=size(x0); len=m*n; %number of pixels x=reshape(x0,len,1); %convert to [len:1] xpdf=hist(x,[0:L-1]); % pdf, 1 x L xpdf=xpdf/len; %Normalize it to get nk/n (eq 3.3-%7)....(len %is equal to sum(xpdf), number of pixels...) sk=xpdf*triu(ones(L));%CDF (eq 3.3-8) y0=zeros(m,n); for k=0:L-1 if (xpdf(k+1) > 0) list=find(x0 ==k); %find value in input image

y0(list)=sk(k+1)*L; %pixel end end

%map sk value for each k valued

y=reshape(y0,len,1); %convert to [len:1] ypdf=hist(y,[0:L-1])/len; % pdf, 1 x L figure(1)subplot(311),stem([0:L1],xpdf,'.'),title('histogram, original') subplot(312),stem([0:L-1],sk,'.'),title('transformation') subplot(313),stem([0:L-1],ypdf,'.'),title('histogram, equalized') figure(2); colormap('gray'); image(y0); y0=uint8(y0); imwrite(y0,'6010d_eq.tif','TIFF'); Output Code presented above outputs these results. Output Image: Input Image:

Histograms of Input & Output Image and Transfer Function

Histogram Specification: This code is used to match histogram of input image with a desired histogram. MatLab Code: clc; clear all; colormap('gray'); L=256; x0=imread('Lvr2i.tif'); x0=double(x0); %input image [m,n]=size(x0); len=m*n; %number of pixels x=reshape(x0,len,1); %convert to [len:1] xpdf=hist(x,[0:L-1]); % pdf, 1 x L xpdf=xpdf/len;%Normalize it to get nk/n (eq 3.3-7)....(len is equal to sum(xpdf), number %of pixels...) sk=xpdf*triu(ones(L));%CDF (eq 3.3-8), (eq 3.3-13)

%Histogram Specification zd_pdf(1:L)=1; %desired histogram of output image ext = sin(0:pi/255:pi); zd_pdf=zd_pdf+ext; %desired histogram of output image zd_pdf = zd_pdf / sum(zd_pdf); %normalize zk=zd_pdf*triu(ones(L)); %G(z), CDF (eq 3.3-14) %iteration(eq 3.3-17) % hist. matching mapping=zeros(256); z0=zeros(m,n); for q=1:L for p=mapping(q)+1:L if ((zk(p)-sk(q)) >= 0) mapping(q) = p; list=find(x0 == q-1); a=size(list);%find value %in input image z0(list)=p; %map sk value for each k valued %pixel break; end end end z=reshape(z0,len,1); %convert to [len:1] zpdf=hist(z,[0:L-1])/len; % pdf, 1 x L figure(1),subplot(411),stem([0:L1],xpdf,'.'),title('histogram, original') subplot(412),stem([0:L-1],zd_pdf,'.'),title('desired pdf') subplot(413),stem([0:L-1],zk,'.'),title('transformation') subplot(414),stem([0:L-1],zpdf,'.'),title('histogram, matched') figure(2); colormap('gray'); image(z0); z0=uint8(z0); imwrite(z0,'Lvr2i_match.tif','TIFF');

Output This code outputs an image and several plots given below. Output Image: Input Image:

Histograms and Transfer Function:

You might also like