[EE440] Lab1Report Kien Cuong Hung

Embed Size (px)

DESCRIPTION

chi la lab thoi ma hi hi

Citation preview

EE440 Lab 1 Report

Names: Huynh Nhu Kien Ha Xuan Cuong Nguyen Phuc Bao HungClass: 10ECE

1/ Linear stretching:Code:%-----------linear stretching----------im = imread('3_1.jpg'); % Read image% im=imread('3_2.jpg');subplot(221);imshow(im),title('Original Image'); % Display the imagehsv= rgb2hsv(im); % Convert the image from RGB colormap to HSV colormapV= hsv(:,:,3); % Assign the intensity of the HSV image to Vsubplot(222),imhist(V),title('Histogram of the Intensity');V= uint8(255*(V-min(V(:)))/(max(V(:))-min(V(:)))); % Algorithm and scale % the Intensity from [0 1] to [0 255]V=double(V)/255; % Rescale the Intensity back to [0 1]hsv(:,:,3)=V; % Reassign V intonewIm= hsv2rgb(hsv); % Convert the image back to RGB colormapsubplot(223);imshow(newIm),title('Stretched Image');subplot(224),imhist(V),title('Histogram of new Image Intensity');

2/ Histogram Equalization:Code:%------------ Histogram equalization---------------im=imread('3_1.jpg');% im=imread('3_2.jpg');hsv=rgb2hsv(im); % Convert the image to HSV colormapV=hsv(:,:,3); % Assign the Intensity of the image to VV=uint8(255*V); % Scale the intensity from [0 1] to [0 255][nk,x]=imhist(V);subplot(221);imhist(V),title('Histogram of the intensity');subplot(222);imshow(im),title('Original Image');MN=numel(V); % number of elements in Vsk=round(255/MN*(cumsum(nk))); % Calculate the cdf of Vfor i=1:MN for j=1:256 if(V(i)==j) V(i)=sk(j); % Replace each Intensity value with a new one after % taking cumulative sum algorithm break end endendsubplot(223);imhist(V),title('Histogram of new Image Intensity');V=double(V)/255; % Convert the Intensity back to scale [0 1]hsv(:,:,3)=V; % Reassign the Intensity to the HSV imageNewIm=hsv2rgb(hsv); % Convert the HSV image to RGB imagesubplot(224);imshow(NewIm),title('Equalized Image');

3/ Histogram Matching:Code:clc; clear;%----------------choose an image to enhance-------------------------- input=imread('3_1.jpg');% input=imread('3_2.jpg'); %----------------histogram specification---------------------------- hsv=rgb2hsv(input);V=hsv(:,:,3);NV=uint8(255*V);V=uint8(255*V);[nk,x]=imhist(V); % original histogramMN=numel(V); % number of values in Vsk=round(255/MN*(cumsum(nk))); % transformation function skz=0:1:255;d=normpdf(z,100,60); % desired histogramgz=round(255*(cumsum(d))); % transformation function G(z) % r to sfor i=1:MN for j=1:256 if(V(i)==(j-1)) V(i)=sk(j); break end endend% s to zfor i=1:MN j=1; if(V(i)gz(j)&&j