Resizepgm

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Exercise No: 9 Date:

PROGRAM TO RESIZE THE IMAGE AND STORE IN NEW FILE

Aim:
Write the MATLAB program to resize the given image and store the image
in the given folder.
Apparatus Required:
 Personal Computer
 MATLAB tool

PROGRAM:

% REDUCE THE GIVEN IMAGE BY 2


I=imread('cowpasture.jpg');
J=imresize(I,0.5);
figure, imshow(I);
title('original image');
figure, imshow(J);
title('resized image');

% TO RESIZE THE IMAGE ACCORDING TO THE NUMBER OF ROWS


AND COLUMNS NEEDED
I=imread('deer2.jpeg');
J=imresize(I,[126 126]);
figure, imshow(I);
title('original image');
figure, imshow(J);
title('resized image 126 X 126');

% TO RESIZE THE IMAGE FOR THE REQUIRED NUMBER OF ROWS


AND NUMBER OF COLUMN IS UNSPECIFIED
I=imread('deer2.jpeg');
J=imresize(I,[256 NaN]);
figure, imshow(I);
title('original image');
figure, imshow(J);
title('resized image 256 X NaN');
% TO RESIZE THE IMAGE AND STORE THAT IMAGE IN THE
CURRENT FOLDER
I=imread('deer2.jpeg');
J=imresize(I,[126 126]);
imwrite(J,'deer2reduced.jpeg')
figure, imshow(I);
title('original image');
figure, imshow(J);
title('resized image 126 X 126');

OUTPUT:
1. REDUCE THE GIVEN IMAGE BY 2

2. TO RESIZE THE IMAGE ACCORDING TO THE NUMBER OF ROWS


AND COLUMNS NEEDED

3. TO RESIZE THE IMAGE FOR THE REQUIRED NUMBER OF ROWS


AND NUMBER OF COLUMN IS UNSPECIFIED

4. TO RESIZE THE IMAGE AND STORE THAT IMAGE IN THE


CURRENT FOLDER
STORE THE REDUCED IMAGE FILE AS deer2reduced.jpeg
Procedure:
1. Start the MATLAB program.
2. Go to editor window and type the program.
3. Choose the current folder (D:\matlabprogram\Animal) that contain image file
that is to be resized.
4. Save Run the program.Check for error, if you have correct it.Check the result.

5. Stop the program

Result:

Date:
Staff Signature:
Exercise No: 10 Date:

PROGRAM TO RESIZE THE ALL THE IMAGES AND STORE IN NEW FOLDER

Aim:
Write the MATLAB program to resize all the images and store the images
in new folder.
Apparatus Required:
 Personal Computer
 MATLAB tool

PROGRAM:

%PROGRAM TO RESIZE THE IMAGES IN ONE FOLDER AND STORE


THE RESIZED IMAGE IN NEW FOLDER
clear all;
close all;
clc;
f='animal';
d=ls(f);
d(1,:)=[];
d(1,:)=[];
mkdir('animalnew1')
for i=1:size(d)
I=imread(fullfile(f,d(i,:)));
imshow(I);
I=imresize(I,[256 256]);
imwrite(I,fullfile('animalnew1',strcat(num2str(i),'.jpeg')));
imshow(I)
end
OUTPUT:
IMAGE BEFORE RESIZING:

IMAGE AFTER RESIZING:

Procedure:
1. Start the MATLAB program.
2. Go to editor window and type the program.
3. Choose the location where current folder exists(D:\matlabprogram)and having
image files that is to be resized.
4. Save Run the program.Check for error, if you have correct it.Check the result.
5. Now this program will create a new folder name animalnew1 folder.And this
contains a resized images.
6. Stop the program
Result:

Date:
Staff Signature:
Exercise No: 11 Date:

PROGRAM TO ROTATE THE GIVEN IMAGE AND MERGE ALL THE


SELECTED IMAGES

Aim:
Write the MATLAB program to rotate the given image and also to merge
the selected images.
Apparatus Required:
 Personal Computer
 MATLAB tool

PROGRAM:

%PROGRAM FOR IMAGE ROTATION AND IMAGE MERGING

% IMAGE ROTATION
clear all;
close all;
clc;
I=imread('3a.jpeg');
figure,
imshow(I);
title('original image');
J=imread('4a.jpeg');
k=imrotate(I,45);
figure,
imshow(J);
figure,
imshow(k);
title('Image after 45 degree rotation');

% IMAGE MERGING
I=imread('3a.jpeg');
J=imread('4a.jpeg');
CI=cat(2,I,J);
figure,
montage(CI);
title('2-merged image');
I1=imread('1a.jpeg');
I2=imread('2a.jpeg');
I3=imread('3a.jpeg');
I4=imread('4a.jpeg');
I5=cat(4,I1,I2,I3,I4)
figure,
montage(I5);
title('4-MERGED IMAGE');
OUTPUT:
Procedure:

1. Start the MATLAB program.


2. Go to editor window and type the program
3. Choose the location where image file exist ex D:\matlabprogram\animalnew1.
4. Save Run the program.Check for error, if you have correct it.Check the result.
5. Now this program will rotate the given image and also merge the selected images.
6. Stop the program
Result:

Date:
Staff Signature:
Exercise No: 12 Date:

PROGRAM TO INSERT TEXT ON THE GIVEN IMAGE

Aim:
Write the MATLAB program to insert text on the image.
Apparatus Required:
 Personal Computer
 MATLAB tool

PROGRAM:

%PROGRAM TO INSERT TEXT ON THE IMAGE

clear all;
close all;
clc;
I=imread('horse.jpeg');
figure,
imshow(I);
title('ORIGINAL IMAGE');
J=insertText(I,[300 300],'BEAUTIFUL HORSE');
figure,
imshow(J);
title('AFTER INSERTING TEXT IN IMAGE')
OUTPUT:

Procedure:

1. Start the MATLAB program.


2. Go to editor window and type the program.
3. Choose the location where image file exist ex D:\matlabprogram\animal.
4. Save Run the program.Check for error, if you have correct it.Check the result.
5. Now this program will insert the required text in the image in the required
position.
6. Stop the program
Result:

Date:
Staff Signature:
Exercise No: 13 Date:

PROGRAM TO SEPARATE OBJECTS IN THE GIVEN IMAGE

Aim:
Write the MATLAB program to separate objects from the given image.
Apparatus Required:
 Personal Computer
 MATLAB tool

PROGRAM:
% PROGRAM FOR OBJECT SEGMENTATION
clc;
clear all;
close all;
inpict=imread('toolspic2.png');
figure, imshow(inpict);
title('original image');
%cropped from thumpnail
bpict=rgb2gray(inpict)<240;
%pick a threshold to isolate from Background
S=regionprops(bpict,'boundingbox','filledimage');
C=cell(numel(S),1);
for n=1:numel(S)
%get mask of object only
mk=S(n).FilledImage;
%get corresponding rectangular area of original image
bb=floor(S(n).BoundingBox);
samp=inpict(bb(2):bb(2)+bb(4)-1,bb(1):bb(1)+bb(3)-1,:);
%remove adjacent object fragments from rectangular sample
samp(repmat(~mk,[1 1 size(inpict,3)]))=255;
%store the image
c{n}=samp;
end
%just plot the images for viewing

for n=1:numel(S)
subplot(3,4,n)
imshow(c{n},'border','tight')
end
OUTPUT:IMAGE BEFORE AND AFTER OBJECT SEPARATION

Procedure:

7. Start the MATLAB program.


8. Go to editor window and type the program.
9. Choose the location where image file exist ex D:\matlabprogram\24.09.22.
10. Save Run the program.Check for error, if you have correct it.Check the result.
11. Now this program will separate the objects in the image.
12. Stop the program
Result:

Date:
Staff Signature:

You might also like