You are on page 1of 3

OBJECTIVE:

To conduct different operations on images

THEORY:

Unary operations on the image


Unary operations on the image are mathematical operations whose input is a pixel intensity value, and
the output is a changed intensity value of the same pixel. The operation is performed for all of the pixels
in the image, meaning that an unary operator produces an image for each given input image. A scheme
of an unary operation is given with Fig 2.1

Fig.2.1 Unary image operations scheme

Unary operation can be any mathematical function that changes the intensity values of the pixels in an
image. Co-domain of the function does not have to be equal to its domain. Therefore, if we want to
obtain a meaningful display of an image after performing an unary operation on it, the resulting image
will need to be rescaled. Images whose pixel values are given with a class double should be scaled to the
interval [0;1], whereas the images whose pixel values are given with a class integer should be scaled to
the interval [1;255]. MATLAB function imagesc() does an automatic scaling to the required interval and
displays it.

An example:

>> [img, map] = imread(’medalja_kamenita_vrata.png’);


>> img = double(img); % most of the functions require input arguments of a class double
>> imgU = sqrt(img); % performing an unary operation
>> max(imgU(:)) % display the maximal value
ans =
15.9687 % maximal value is not 255 anymore
>> imagesc(imgU) % scale and display the image simultaneously
>> colormap(gray) % change the color palette

Tasks:

1. Compare the function imagesc with the functions image and imshow
2. Read the image. Create a grayscale image out of that image (function rgb2gray()). Perform the
following unary operations on that image: logarithmic function, square and square root, and
compare what happened to the different parts of the image.

Binary operations on the image


4
Binary operations are the operations that take two input images to perform a mathematical operation.
The scheme of the binary operation is given in Fig 2.2

Fig.2.2 Binary image operations scheme

Binary options require the input images sizes to be equal. The options for this are following: To decrease
the size of the bigger image, to increase the size of the smaller image, or to change the size of the both
images. Also, the colorspace of both images needs to be the same (RGB, HSV or other; or black and
white), ie. both images need to be indexed and have the same color palette.

An example:

>> [img1, map] = imread(’medalja_kamenita_vrata.png’);


>> [img2, map] = imread(’medalja_dubrovnik.png’);
>> whos
Name Size Bytes Class Attributes
img1 600x600 360000 uint8 % The dimensions of the 1st image are: 600x600
img2 545x548 298660 uint8 % The dimensions of the 1st image are: 545x548
map 0x0 0 double
>> img2 = imresize(img2,[600 600],’bilinear’);
>> size(img2)
ans =
600
600 % now the first image is also 600x600
>> img = double(img1)+double(img2); % summation of the images
>> imagesc(img), colormap(gray) \begin{verbatim}

Tasks:

1. Pick two grayscale images with different sizes from the USC-SIPI image database. Try several
binary operations on them: summation, multiplication, subtraction. Display the results and
explain them.
2. Try the same thing in the RGB images. Display the results. Explain what happened.

Word of today lab

5
The most common binary operation in the practice is the subtraction of the images. It is used with a
purpose of emphasizing the contrast. In this type of applications, one of the images usually contains a
regular scene (the background), while the other one contains an objects (or more of them) which we
want to emphasize, positioned in front of the same background. Assuming that the background didn’t
change, the subtraction of the images results in a new images whose pixel values are the largest exactly
in the places where our objects of interest are positioned.

Conclusion:

You might also like