Vous êtes sur la page 1sur 31

1

2
3
1
JIMMA UNIVERSITY

INSTITUTE OF TECHNOLOGY

SCHOOL OF COMPUTIG

Title:- Basic arithmetic and logical operations over an image

Group members:

Name ID_NO

1. Mehariw Zewudie…………………….ru0469/08

2. Yibelu Sbhat ………………………….ru3325/07

3. Yonas Getachew ……………………….. ru 0491/08

4 .Marshet Tesfaye………………………..ru0494/08

5.Nebil Mohammed………………………….Ru1334/07

i
ii
Table of Contents
Title ............................................................................................................................................................. 16
Objective ..................................................................................................................................................... 16
Theory ......................................................................................................................................................... 16
Materials used ............................................................................................................................................ 16
Procedures .................................................................................................................................................. 17
Conclusion ................................................................................................................................................... 23

1
2
Lab Report

Objectives
Object of this lab is how the basic arithmetic operation can be done over a given image. How
image can be added, subtracted, multiplied and also divided by image.

In addition it incorporate how to use basic logic gate operations like AND ,OR , XOR and NOT
on a given image.

Theory
In this lab how the image can be added, subtracted, multiplied and divided pixel by pixel using
mat lab software. Adding, subtracting, multiplying and dividing two images can produce image,
but result is different from the original image, because the addition, subtraction, multiplying and
division, AND, OR, XOR and NOT of two different images produce one image.

Materials
In this lab activity we use both hardware and software:

Hardware:
 Computer
Software:
 Matlab

1
Procedure:
Process of how to add, subtract, multiply and divide images looks like the following:
Image Addition
step1: import image file into the current directory
step2: clc, clear the matlab workspace
step3: I=imread(‘image1.jpg’);
subplot(2,2,1);
title(‘image one’);
imshow(i);
step4: j=imread(‘image2,jpg’);
subplot(2,2,2);
title(‘image two’);
imshow(j);
step5:k=imadd(i,j);
subplot(2,2,3);
title(‘added image’);
imshow(k);

Image subtraction
step1: import image file into the current directory
step2: clc, clear the matlab workspace
step3: i=imread(‘image1.jpg’);
subplot(2,2,1);
title(‘image one’);
imshow(i);
step4: j=imread(‘image2,jpg’);
subplot(2,2,2);
title(‘image two’);
imshow(j);
step5:k=imsubtract(i,j);
subplot(2,2,3);
title(‘added image’);
imshow(k);

2
Image multiplication
step1: import image file into the current directory
step2: clc, clear the matlab workspace
step3: i=imread(‘image1.jpg’);
subplot(2,2,1);
title(‘image one’);
imshow(i);
step4: j=imread(‘image2,jpg’);
subplot(2,2,2);
title(‘image two’);
imshow(j);
step5:k=immultiply(i,j);
subplot(2,2,3);
title(‘added image’);
imshow(k);

Image Division
step1: import image file into the current directory
step2: clc, clear the matlab workspace
step3: i=imread(‘image1.jpg’);
subplot(2,2,1);
title(‘image one’);
imshow(i);
step4: j=imread(‘image2,jpg’);
subplot(2,2,2);
title(‘image two’);
imshow(j);
step5:k=imdivide(i,j);
subplot(2,2,3);
title(‘added image’);
imshow(k);

3
Image AND
step1: import image file into the current directory

step2: clc, clear the matlab workspace


step3: I=imread (‘image1.jpg’);
Subplot (2, 4, 1);
title (‘Image One’);
imshow(I);
step4: J=imread (‘image2.jpg’);
Subplot (2, 4, 2);
title (‘Image Two’);

Step 5: L=bitand (I, .J);


Subplot (2, 4, 3)
imshow (L)
title (‘and’);

Image OR
step1: import image file into the current directory

step2: clc, clear the matlab workspace


step3: I=imread (‘image1.jpg’);
Subplot (2, 4, 1);
title (‘Image One’);

step4: J=imread (‘image2.jpg’);


Subplot (2, 4, 2);
title (‘Image Two’);

Step 5: M=bitor (I, J);


Subplot (2, 4, 4);
Imshow (M);
title (‘OR’);

4
Image XOR
step1: import image file into the current directory

step2: clc, clear the matlab workspace


step3: I=imread (‘image1.jpg’);
Subplot (2, 4, 1);
title (‘Image One’);
step4: J=imread (‘image2.jpg’);
Subplot (2, 4, 2);
Title (‘Image Two’);

step 5: N=bitxor (I, J);


Subplot (2, 4, 5);
Imshow (N);
title (‘XOR’)
O=bitcmp(I);
Subplot (2, 4, 6);
imshow (O);
title (‘NOT’);

5
Result:-
In this lab we have got different images that can different the original images.
Examples are the followings;-

1. Image addition :
Adding two images can produce one image
To add two images, the images must have the size.

Image1 original Image2 original

6
New result from the two images.

2. Image Subtraction:
Two images must have the same size.
Subtract one image from other image produce new image.

Image1 - image2

7
=
New image

8
3. Image Multiplication
Multiplications of two images produce new image.

Image1 * image2

New image

9
4. Image division

Image 1 / image 2

New image

10
5 .Image AND

New image

11
6. Image OR

New image

12
7 .Image XOR and NOT

13
Discussion:-
In this section of the lab report we tried to discuss briefly about image addition,
subtraction, multiplication, division and logical operations (AND, OR, XOR,
NOT) which results in obtaing different image quality. It is obvious that we get
image with various qualities at the time we apply these arithmetic and logical
operations on the given image(original image).These report writing is concluded
by incorporating tittle, objective, theory, materials used, procedure and results
obtained.

14
Table of Contents
Title ............................................................................................................................................................. 16
Objective ..................................................................................................................................................... 16
Theory ......................................................................................................................................................... 16
Materials used ............................................................................................................................................ 16
Procedures .................................................................................................................................................. 17
Conclusion ................................................................................................................................................... 23

15
Lab3 report

Title:
Image Cropping, Resizing, Flipping, and Rotation

Objective:
The objectives of this lab activity are Cropping, Resizing, Flipping and Rotating the image using
matlab script.

Theory
In world technology develops rapidly and solves many problems that is very difficult to solve
manually. In order to develop this system lab practice is very important. So we are going to
practices the scripts on mat lab software .This practices also increase our understanding how
image can be cropped, resized, flip and rotated. Cropping is very important when we need only
certain part of the image. Big image need large area of storage and while we have small storage
we have to resize the image using different techniques in matlab. The same is true for flipping
and rotating the image in case studying image in different views.

Materials used
To perform this lab practices we use different hard ware and software materials. These materials
are;

Hard ware tools

 Desk top

Software tools

 Matlab 2016
 Adobe reader: - to read the given pdf materials.

16
Procedures
In order to Crop, Resize, Flip and rotate an image :
1. We write mat lab script that read image from it’s folder
2. We give position by which order the images are displayed
3. Write mat lab script to display the image
4. Then Cropping, Resizing, Flipping and Rotating

5.
6. Matlab code for image cropping

%reading/loading image to matlab


7. I = imread('image1.jpg');
8. figure
9. imshow(I)
10. title('Original Image');
11. % using imtool to see the image details like
12.
13. imtool(I)
14. x1 = 1;
15. x2 =225;
16. y1 = 413;
17. y2 = 826;
18. xmin = x1;
19. ymin = y1;
20. width = x2-x1;
21. height = y2-y1;
22. I2 = imcrop(I, [xmin ymin width height]);
23. figure
24. imshow(I2);
25. title('croped image using coordinate values');
26.
27.An output:

17
Matlab code for image Resizing
1. image Enlarging
I = imread('image1.jpg');
figure
imshow(I),
title('Original Image');
imshow(I2);
Ib = imresize(I,2);
figure
imshow(Ib), ...
title('Enlarged Image with bilinear interpolation');

The output :

18
2. for shrinking

% reading original image to be shrinked image1.jpg.


I = imread('image1.jpg');
figure
imshow(I);
title('original image')
% using default matlab shrinking function
I2 = imresize(I,0.5);
figure
imshow(I2);
title('Shirinking image by half, default function');
%using nearest interpolation for shrinking by half
I3 = imresize(I,0.5,'bilinear');
figure
imshow(I3);
title('shrinking using bilinear interpolation')

Out put

19
Image filliping and rotation
Image can be flipped in different direction

a. Flipping upside down

I = imread('image1.jpg');
subplot(2,2,1);
imshow(I);
title('Original image')
I2=rgb2gray(I);
subplot(2,2,2);
imshow(I2);
title('Original image converted to grayscale')
%Flipping upside down
J = flipud(I2);
subplot(2,2,3)
imshow(J)
title('Flipped upside-down')

Output

20
a. flipping from left to right

I = imread('image1.jpg');
subplot(2,2,1);
imshow(I);
title('Original image')
I2=rgb2gray(I);
subplot(2,2,2);
imshow(I2);
title('Original image converted to grayscale')
K = fliplr(I2);
subplot(2,2,3), imshow(K);
title('Flipped left-right')

21
a. rotation of images by certain angle

I = imread('image1.jpg');
subplot(2,2,1);
imshow(I);
title('Original image')
I2=rgb2gray(I);
subplot(2,2,2);
imshow(I2);
title('Original image converted to grayscale')
Ir= imrotate(I,35);
subplot(2,2,3),
imshow(Ir);
title('Rotated Image using default Interpolation');

22
Conclusion
As we know knowledge comes from practices. In this practice we understand how images can
cropped, resized, flipped and rotated in different direction. And also we understand the
importance of this cropping, flipping, resizing and rotating an image in different areas of study.

23

Vous aimerez peut-être aussi