Lab-8 BMS

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Lab-8

Processing Techniques and Statistics on Images in Matlab


Objective

• To give overview about images and its types


• To overview Digital image processing and Biomedical Imaging
• Overview of Statistical analysis on Images in Matlab

8.1 Image
An image is defined as a two-dimensional function(x,y), where x and y are spatial
coordinates, and the amplitude of F at any pair of coordinates (x,y) is called the intensity of
that image at that point. When x,y, and amplitude values of F are finite, we call it a digital
image. an image can be defined by a two-dimensional array specifically arranged in rows.
Digital Image is composed of a finite number of elements, each of which elements have a
particular value at a particular location. These elements are referred to as picture elements,
image elements, and pixels. A Pixel is most widely used to denote the elements of a Digital
Image.
8.1.1 Types of an image
• BINARY IMAGE– The binary image as its name suggests, contain only two-pixel
elements i.e., 0 & 1, where 0 refers to black and 1 refers to white. This image is also
known as Monochrome.
• BLACK AND WHITE IMAGE– The image which consist of only black and white color
is called BLACK AND WHITE IMAGE.
• 8-bit COLOR FORMAT– It is the most famous image format. It has 256 different
shades of colors in it and commonly known as Grayscale Image. In this format, 0
stands for Black, and 255 stands for white, and 127 stands for gray.
• 16-bit COLOR FORMAT– It is a color image format. It has 65,536 different colors in
it. It is also known as High Color Format. In this format the distribution of color is
not as same as Grayscale image.
A 16-bit format is divided into three further formats which are Red, Green and Blue. That
famous RGB format.

8.2 Digital Image Processing


Digital Image Processing means processing digital image by means of a digital computer.
We can also say that it is a use of computer algorithms, to get enhanced image to extract
some useful information.
8.3 Biomedical Imaging
Biomedical imaging concentrates on the capture of images for both diagnostic and
therapeutic purposes. Snapshots of in vivo physiology and physiological processes can be
garnered through advanced sensors and computer technology. Biomedical imaging technologies
utilize either x-rays (CT scans), sound (ultrasound), magnetism (MRI), radioactive
pharmaceuticals (nuclear medicine: SPECT, PET) or light (endoscopy, OCT) to assess the current
condition of an organ or tissue and can monitor a patient over time over time for diagnostic and
treatment evaluation

8.4 Matlab Usage in biomedical imaging


The use of images in biomedical engineering is increasingly common. Medical images can
be acquired using modalities such as magnetic resonance (MR), X-ray computed tomography (CT)
and ultrasound (US). In this section we will introduce how to read, write, and display general
imaging data using MATLAB
.
8.4.1 Example
The following example illustrates the use of several built-in image-related MATLAB commands.

% read image
im = imread('pout.tif');
% display image
imshow(im);
% modify image
im(100:120,100:120) = 0;
% save image (saves 'im' array)
imwrite(im, 'fluoro_imwrite.tif');
% save image (saves figure as displayed)
saveas(gcf, 'fluoro_saveas.tif');
The imread command reads imaging data from a file with a name specified by the single
argument. The value returned is a 2-D array of pixel intensities. Images are treated as normal 2-
D arrays in MATLAB. The intensities can be of different types such as int8, single or double, but
within a single image all must have the same type, as with all MATLAB arrays. Imaging data can
be manipulated just like any other MATLAB array, as we can see from the third non-comment
line in the above example in which a rectangular block of pixels has its intensities set to 0.

The imshow command can be used to display a 2-D image in a figure window. The single
argument is the 2-D array of pixel intensities.

This example shows two ways in which the image can be written to an external file. The imwrite
command takes a 2-D array and a file name as its only arguments, so the image data written to
the file depends only on the array and not on any figure currently being displayed. The saveas
command is used in this example to save the data in the current figure (gcf means get current
figure). Therefore, any changes made to the displayed figure will also be saved, but any changes
made to the original array since it was displayed (as in the example above) will not be saved. In
this example, save as saves the figure as an image, but it can also be used to save in the native
MATLAB figure format, which has a “.fig” file extension.

Both the imread and imwrite commands can handle a range of different imaging formats, such
as bmp, png and tif. For a full list of supported formats, type imformats at the MATLAB command
window. Normally, just adding the extension to the file name is enough to tell MATLAB which
format we want to use.

8.5 Image tool and Image View App

• imtool opens the Image Viewer app in an empty state. Use the File menu
options Open or Import from Workspace to choose an image for display.
• imtool(I) displays the grayscale image I in the Image Viewer.
• imtool(I,[low high]) displays the grayscale image I in the Image Viewer, specifying the
display range for I in the vector [low high]. The value low (and any value less than low) is
displayed as black, the value high (and any value greater than high) is displayed as white.
Values in between are displayed as intermediate shades of gray. The Image Viewer uses
the default number of gray levels. If you use an empty matrix ([]) for [low high], the Image
Viewer uses [min (I(:)) max(I(:))]; the minimum value in I is displayed as black, and the
maximum value is displayed as white.
• imtool(RGB) displays the true color image RGB in the Image Viewer.
• imtool(BW) displays the binary image BW in the Image Viewer. Pixel values of 0 display as
black; pixel values of 1 display as white.
• imtool(X,map) displays the indexed image X with colormap map in the Image Viewer.
8.5.1 Example

Display an image from a file.


imtool('board.tif')

Display an indexed image.


[X,map] = imread('trees.tif');
imtool(X,map)

Display a grayscale image.


I = imread('cameraman.tif');
imtool(I)

Display a grayscale image, adjusting the display range.


h = imtool(I,[0 80]);
close(h)
8.6 Image Statistics
8.6.1 Mean Square Error
The mean squared error (MSE) tells you how close a regression line is to a set of
points. It does this by taking the distances from the points to the regression line (these
distances are the “errors”) and squaring them. The squaring is necessary to remove any
negative signs. It also gives more weight to larger differences. It’s called
the mean squared error as you’re finding the average of a set of errors. The lower the
MSE, the better the forecast

Figure 7.1 Mean Square Error Formula

8.6.1.1 Example

%Read Image
ref = imread('pout.tif');
%Show Image
imshow(ref)
% Applying Filter for adding noise
A = imnoise(ref,'salt & pepper', 0.02);
%Show Image
imshow(A)
%Applying Mean Squared Error
err = immse(A, ref);
%Show Image
fprintf('\n The mean-squared error is %0.4f\n', err);

8.6.2 Structural Similarity Index (SSIM)


The Structural Similarity (SSIM) index is a method for measuring the similarity
between two images. The SSIM index can be viewed as a quality measure of one of the images
being compared, provided the other image is regarded as of perfect quality.
Figure 7.2 Structural Similarity Formula
8.6.2.1 Example

%Read Image
ref = imread('pout.tif');
% Making Filter
H = fspecial('Gaussian',[11 11],1.5);
%Applying filter
A = imfilter(ref,H,'replicate');
% Ploting the Image before and after applying filter
subplot(1,2,1); imshow(ref); title('Reference Image');
subplot(1,2,2); imshow(A); title('Blurred Image');
% Making array and applying Structural Similariity Index
[ssimval, ssimmap] = ssim(A,ref);
% Print value of SSIM
fprintf('The SSIM value is %0.4f.\n',ssimval);
% Showing Figure of After Applying SSIM
figure, imshow(ssimmap,[]);
%Giving Title with Sprintf command
title(sprintf('ssim Index Map - Mean ssim Value is %0.4f',ssimval));

You might also like