0% found this document useful (0 votes)
333 views8 pages

Image Processing Using Matlab Practicals

The document contains 6 programs describing image processing techniques. Program 1 converts an RGB image to grayscale by eliminating hue and saturation. Program 2 thresholds a grayscale image into multiple levels using grayslice. Program 3 implements grayslice without using the gray command. Program 4 calculates the compression ratio of images saved at different quality levels. Program 5 finds the Fourier transform, shifted quadrants, and magnitude and phase of an image. Program 6 rotates an image and studies the effect of rotation on the Fourier transform of an image.

Uploaded by

rb229
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)
333 views8 pages

Image Processing Using Matlab Practicals

The document contains 6 programs describing image processing techniques. Program 1 converts an RGB image to grayscale by eliminating hue and saturation. Program 2 thresholds a grayscale image into multiple levels using grayslice. Program 3 implements grayslice without using the gray command. Program 4 calculates the compression ratio of images saved at different quality levels. Program 5 finds the Fourier transform, shifted quadrants, and magnitude and phase of an image. Program 6 rotates an image and studies the effect of rotation on the Fourier transform of an image.

Uploaded by

rb229
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/ 8

PROGRAM 1 : TO CONVERT RGB IMAGE TO GRAY.

rgb2gray : Convert RGB image or colormap to grayscale Syntax I = rgb2gray(RGB) newmap = rgb2gray(map) Description I = rgb2gray(RGB) converts the truecolor image RGB to the grayscale intensity image I. rgb2gray converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance.

>> x=imread('1.jpg'); >> a=rgb2gray(x); >> imshow(a),title('hand')

% read image 1.jpg and store as x % converts x into gray from RGB and store in a % shows a , and title is hand

PROGRAM 2 : TO STUDY GRAYSLICE.

Grayslice : Convert grayscale image to indexed image using multilevel thresholding Syntax X = grayslice(I, n) Description X = grayslice(I, n) thresholds the intensity image I returning an indexed image in X. grayslice uses the threshold values:

X = grayslice(I, v) thresholds the intensity image I using the values of v, where v is a vector of values between 0 and 1, returning an indexed image in X

>> x=imread('1.jpg'); >> a=rgb2gray(x); %converts image x to gray and stored in variable a >>figure,imshow(grayslice(a,128),gray(128)),title('grayslice 128') %shows image with grayslice 128 with . 128 gray levels and title grayslice 128 >>figure,imshow(grayslice(a,64),gray(64)),title('grayslice 64') >>figure,imshow(grayslice(a,32),gray(32)),title('grayslice 32') >>figure,imshow(grayslice(a,16),gray(16)),title('grayslice 16') >>figure,imshow(grayslice(a,8),gray(8)),title('grayslice 8')

PROGRAM 3 : TO IMPLEMENT GRAYSLICE WITHOUT GRAY() COMMAND. Without using gray() command {The dynamic range of gray level is constant}

>> x=imread('1.jpg'); >> a=rgb2gray(x); >> figure,imshow(grayslice(a,128)),title('grayslice 128') >> figure,imshow(grayslice(a,64)),title('grayslice 64') >> figure,imshow(grayslice(a,32)),title('grayslice 32') >> figure,imshow(grayslice(a,16)),title('grayslice 16') >> figure,imshow(grayslice(a,8)),title('grayslice 8')

PROGRAM 4: TO CALCULATE THE COMPRESSION RATIO OF 8 BIT GRAY SCALE IMAGE: Imfinfo : Information about graphics file Syntax info = imfinfo(filename) Description info = imfinfo(filename) attempts to infer the format of the file from its contents.

>>k=imfinfo(1.jpg) % shows the information of image

Imwrite : Write image to graphics file Quality : Decides the quality of file

>> x=imread('1.jpg'); >> imwrite(x,('1-1.jpg'),'Quality',80); >> imwrite(x,('1-2.jpg'),'Quality',20);

% writes file named 1-1.jpg with quality 80 percent of image 1.jpg % writes file named 1-2.jpg with quality 20 percent of image 1.jpg

A. 80% Quality

B.

20% Quality

IB : Image bits CB : Compression bits CR : Compression ratio

% From the above results we can see that as the quality decreases , the compression ratio increases

PROGRAM 5 : TO FIND FOURIER TRANSFORM OF AN IMAGE, STUDY THE SHIFTING QUADRANTS AND CALCULATE MAGNITUDE AND PHASE OF AN IMAGE. fft2 : 2-D discrete Fourier transform Syntax Y = fft2(X) Description Y = fft2(X) returns the two-dimensional discrete Fourier transform (DFT) of X, computed with a fast Fourier transform (FFT) algorithm. The result Y is the same size as X.

Fftshift : Shift zero-frequency component to center of spectrum Syntax Y = fftshift(X)

Description Y = fftshift(X) rearranges the outputs of fft, fft2, and fftn by moving the zero-frequency component to the center of the array. It is useful for visualizing a Fourier transform with the zero-frequency component in the middle of the spectrum >>x=imread('1.jpg'); >> y=fft2(x); % calculates fft in 2d array and stores in variable y >>z=fftshift (y); % shifts the Quadrants of Image y and stores in variable z >> imshow(y),title ('Fourier Image '),figure, imshow(z), title (Shifted Quadrants)

>>x=imread(1.jpg); >>y=fft2(x); >>mag=abs(y) >>ph=Angle(y)

% it gives the magnitude of image y % it gives phase angle of image y

Magnitude plot

Phase Plot

PROGRAM : 6 TO ROTATE THE IMAGE imrotate : Rotate image Syntax B = imrotate(A,angle) Description B = imrotate(A,angle) rotates image A by angle degrees in a counterclockwise direction around its center point. To rotate the image clockwise, specify a negative value for angle. imrotate makes the output image B large enough to contain the entire rotated image. imrotate uses nearest neighbor interpolation, setting the values of pixels in B that are outside the rotated image to 0 (zero)

>> x=imread('1.jpg'); >> s=imrotate(x,45); % Rotates image x by 45 degree clockwise >>s1=imrotate(x,90); % Rotates image x by 90 degree clockwise >>s2=imrotate(x,120); % Rotates image x by 120 degree clockwise >>figure ,imshow(s),title('45'),figure ,imshow(s1),title('90'),figure ,imshow(s2),title('120')

45 Program : 6a To study effect of rotation in complex image. >> x=imread('1.jpg'); >> y=rgb2gray(x); >> y1=fft2(y); >> y2=fftshift(y1); >> s=imrotate(y,45); >> s1=fft2(s); >> s2=fftshift(s1); >> imshow(y2), figure , imshow(s2)

90

120

Original FFt image

Rotated FFt Image

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy