Bip Practical
Bip Practical
PRACTICAL: 1
Date:
AIM: To Implement basic operations on Image using MATLAB.
Objectives:-
To study about image formats.
To study about basic arithmetic operations of image.
To implement read, write display image in MATLAB.
Theory
Types of Images
There are three types of images. They are as following:
1. Binary Images
It is the simplest type of image. It takes only two values i.e, Black and White or 0 and 1. The binary image
consists of a 1-bit image and it takes only 1 binary digit to represent a pixel. Binary images are mostly used
for general shape or outline.
For Example: Optical Character Recognition (OCR).
Binary images are generated using threshold operation. When a pixel is above the threshold value, then it
is turned white('1') and which are below the threshold value then they are turned black('0').
2. Gray-scale images
Grayscale images are monochrome images, Means they have only one color. Grayscale images do not
contain any information about color. Each pixel determines available different grey levels. A normal
grayscale image contains 8 bits/pixel data, which has 256 different grey levels. In medical images and
astronomy, 12 or 16 bits/pixel images are used.
Page No.
Biomedical Engineering Department, L. D .College of Engineering, Ahmedabad-15
Biomedical Image Processing(2170308)
3. Colour images
Colour images are three band monochrome images in which, each band contains a different color and the
actual information is stored in the digital image. The color images contain gray level information in each
spectral band. The images are represented as red, green and blue (RGB images). And each color image has
24 bits/pixel means 8 bits for each of the three color band(RGB).
8-bit color is used for storing image information in a computer's memory or in a file of an image. In this
format, each pixel represents one 8 bit byte. It has 0-255 range of colors, in which 0 is used for black, 255
for white and 127 for gray color. The 8-bit color format is also known as a grayscale image. Initially, it
was used by the UNIX operating system.
The 16-bit color format is also known as high color format. It has 65,536 different color shades. It is used
in the system developed by Microsoft. The 16-bit color format is further divided into three formats which
are Red, Green, and Blue also known as RGB format. In RGB format, there are 5 bits for R, 6 bits for G,
and 5 bits for B. One additional bit is added in green because in all the 3 colors green color is soothing to
eyes.
Image Addition
Brief Description
In its most straightforward implementation, this operator takes as input two identically sized images and
produces as output a third image of the same size as the first two, in which each pixel value is the sum of
the values of the corresponding pixel from each of the two input images. More sophisticated versions allow
more than two images to be combined with a single operation.
Page No.
Biomedical Engineering Department, L. D .College of Engineering, Ahmedabad-15
Biomedical Image Processing(2170308)
A common variant of the operator simply allows a specified constant to be added to every pixel.
How It Works
The addition of two images is performed straightforwardly in a single pass. The output pixel values are
given by:
If the pixel values in the input images are actually vectors rather than scalar values (e.g. for color images)
then the individual components (e.g. red, blue and green components) are simply added separately to
produce the output value. If the image format being used only supports, say 8-bit integer pixel values, then
it is very easy for the result of the addition to be greater than the maximum allowed pixel value. The effect
of this depends upon the particular implementation. The overflowing pixel values might just be set to the
maximum allowed value, an effect known as saturation. Alternatively the pixel values might wrap around
from zero again. If the image format supports pixel values with a much larger range, e.g. 32-bit integers or
floating point numbers, then this problem does not occur so much.
Image subtraction
The pixel subtraction operator takes two images as input and produces as output a third image whose pixel
values are simply those of the first image minus the corresponding pixel values from the second image. It
is also often possible to just use a single image as input and subtract a constant value from all the pixels.
Some versions of the operator will just output the absolute difference between pixel values, rather than the
straightforward signed output.
How It Works
The subtraction of two images is performed straightforwardly in a single pass. The output pixel values are
given by:
Or if the operator computes absolute differences between the two input images then:
If the pixel values in the input images are actually vectors rather than scalar values (e.g. for color images)
then the individual components (e.g. red, blue and green components) are simply subtracted separately to
produce the output value. Implementations of the operator vary as to what they do if the output pixel
values are negative. Some work with image formats that support negatively-valued pixels, in which case
the negative values are fine (and the way in which they are displayed will be determined by the
display colormap). If the image format does not support negative numbers then often such pixels are just
set to zero (i.e. black typically). Alternatively, the operator may `wrap' negative values, so that for instance
-30 appears in the output as 226 (assuming 8-bit pixel values).
If the operator calculates absolute differences and the two input images use the same pixel value type, then
it is impossible for the output pixel values to be outside the range that may be represented by the input
pixel type and so this problem does not arise. This is one good reason for using absolute differences.
Page No.
Biomedical Engineering Department, L. D .College of Engineering, Ahmedabad-15
Biomedical Image Processing(2170308)
Image Multiplication
Like other image arithmetic operators, multiplication comes in two main forms. The first form takes two
input images and produces an output image in which the pixel values are just those of the first image,
multiplied by the values of the corresponding values in the second image. The second form takes a single
input image and produces output in which each pixel value is multiplied by a specified constant. This latter
form is probably the more widely used and is generally called scaling. This gray level scaling should not
be confused with geometric scaling.
How It Works
The multiplication of two images is performed in the obvious way in a single pass using the formula:
Note that the constant is often a floating point number, and may be less than one, which will reduce the
image intensities. It may even be negative if the image format supports that. If the pixel values are actually
vectors rather than scalar values (e.g. for color images) then the individual components (e.g. ref{rgb}{red,
blue and green components}) are simply multiplied separately to produce the output value.
If the output values are calculated to be larger than the maximum allowed pixel value, then they may either
be truncated at that maximum value, or they can `wrap around' and continue upwards from the minimum
allowed number again.
Image Division
The image division operator normally takes two images as input and produces a third whose pixel values
are just the pixel values of the first image divided by the corresponding pixel values of the second image.
Many implementations can also be used with just a single input image, in which case every pixel value in
that image is divided by a specified constant.
How It Works
The division of two images is performed in the obvious way in a single pass using the formula:
If the pixel values are actually vectors rather than scalar values (e.g. for color images) than the individual
components (e.g. red, blue and green components) are simply divided separately to produce the output
value. The division operator may only implement integer division, or it may also be able to handle floating
point division. If only integer division is performed, then results are typically rounded down to the next
lowest integer for output. The ability to use images with pixel value types other than simply 8-bit
integers comes in very handy when doing division.
Page No.
Biomedical Engineering Department, L. D .College of Engineering, Ahmedabad-15
Biomedical Image Processing(2170308)
MATLAB CODE:
clc;
clear all;
close all;
% image reading
ori_im=imread('C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg');
%image display
figure,subplot(2,2,1),imshow(ori_im);title('Original color image')
% write image
filename=(strcat('E:\yogita\yogita_mtech\7th&3rd\im_lab\ip_practicals\imwr\','tulipsgray.jpg'));
imwrite(g_im,filename);
k2= imfinfo('tulipsgray.jpg');
subplot(2,2,3),imshow(b1);title('Binary image')
u1=im2uint16(dic1);
Page No.
Biomedical Engineering Department, L. D .College of Engineering, Ahmedabad-15
Biomedical Image Processing(2170308)
% 1) Image addition
dic2 = dicomread('E:\yogita\yogita_mtech\7th&3rd\im_lab\MRI_Brain_Scan\MRI Brain Scan\Series
8\I0000417_anon.dcm');
ad1=imadd(dic1,dic2);
figure,subplot(2,3,1),imagesc(dic1);colormap('gray');title('Image 1');
subplot(2,3,2),imagesc(dic2);colormap('gray');title('Image 2');
subplot(2,3,3),imagesc(ad1);colormap('gray');title('Image Addition');
% 2) Image subtraction
as1=imsubtract(dic1,dic2);
subplot(2,3,4),imagesc(as1);title('Image subtraction');
% 3) Image Multiplication
am1=immultiply(dic1,10);
subplot(2,3,5),imagesc(am1);title('Image Multiplication');
% 3) Image Division
ad2=imdivide(dic1,10);
subplot(2,3,6),imagesc(ad2);title('Image Division');
OUTPUT IMAGE:
Page No.
Biomedical Engineering Department, L. D .College of Engineering, Ahmedabad-15
Biomedical Image Processing(2170308)
OUTPUT IMAGE:
Page No.
Biomedical Engineering Department, L. D .College of Engineering, Ahmedabad-15