0% found this document useful (0 votes)
35 views4 pages

%start With True Color Image: Img Imread Imshow (Img)

This lab handout describes how to display different image types like binary, grayscale, and indexed color images using MATLAB commands. It also explains how to generate and display histograms of images to visualize pixel intensity distributions. The post-lab tasks involve reading images and converting between types, displaying histograms, and applying histogram equalization to improve contrast.

Uploaded by

Iqra Zulfiqar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

%start With True Color Image: Img Imread Imshow (Img)

This lab handout describes how to display different image types like binary, grayscale, and indexed color images using MATLAB commands. It also explains how to generate and display histograms of images to visualize pixel intensity distributions. The post-lab tasks involve reading images and converting between types, displaying histograms, and applying histogram equalization to improve contrast.

Uploaded by

Iqra Zulfiqar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

INSTITUTE OF BIOMEDICAL ENGINEERING & TECHNOLOGY LIAQUAT UNIVERSITY OF

MEDICAL & HEALTH SCIENCES JAMSHORO


Subject: Biosignal Processing Year:3 rd, Semester6th

LAB HANDOUT- 08

Name: Roll No: _____________________

Score: Signature of Tutor: Date:________________

OBJECTIVE:
objective of this lab is to understand
1. How to Display different image types
2. How to do Histogram
3. How to do Histogram Equalization

DISPLAY DIFFERENT IMAGE TYPES

MATLAB COMMAND OPERATION


gray2ind( ) Convert from intensity format to indexed format.
ind2gray( ) Convert from indexed format to intensity format.
ind2rgb( ) Convert from indexed format to RGB format.
mat2gray ( ) Convert a regular matrix to intensity format by scaling.
rgb2gray( ) Convert from RGB to intensity format
rgb2ind( ) Convert from RGB format to indexed format
Im2bw( ) Convert an intensity/indexed/RGB format to a threshold black and white
binary image.
dither Convert from intensity/indexed/RGB format to dithered indexed format with
custom color map.

There are some examples of how to use some conversion commands:

INLAB TASK:

CODE OUTPUT
%Start with true color image
img=imread('skull.jpg')
imshow(img)
INSTITUTE OF BIOMEDICAL ENGINEERING & TECHNOLOGY LIAQUAT UNIVERSITY OF
MEDICAL & HEALTH SCIENCES JAMSHORO
%Convert to Binary or black
and white
img_bin=im2bw(img);
imshow(img_bin)

%Convert to Binary or black


and white
%with Custom threshold
(default is 0.5)
img_bin2=im2bw(img,0.3)
imshow(img_bin2)

%convert to grayscale
img_gray=rgb2gray(img);
imshow(img_gray)

%Redue to indexed color


[img_indexed,
map]=rgb2ind(img,8);
imshow(img_indexed,map)

%reduce to indexed color


%without dithering
[img_nodither, map2]=
rgb2ind(img,8, 'nodither');
imshow(img_nodither, map2)

%reduce to indexed color


%using a custom colormap
map_custom=[
1 1 1; %white
1 0 0; %red
0 0 0] %black
img_custommap=dither(img,
map_custom);
imshow(img_custommap,
map_custom)
%ofcourse you swap colormaps
map_custom2=[
1 1 1; %white
0 0 1; %blue
0 0 0]; %black
imshow(img_custommap,
map_custom2)
INSTITUTE OF BIOMEDICAL ENGINEERING & TECHNOLOGY LIAQUAT UNIVERSITY OF
MEDICAL & HEALTH SCIENCES JAMSHORO

HISTOGRAMS:

Histogram are way of visualizing predominant intensities of an image. As a definition, image Histograms
are a count of the number of pixels that are at a certain intensity. When represented as a plot, the x-axis
is the intensity value, and the y-axis is the number of pixels with that intensity value.

Histogram represents a relative frequency of the appearance of different levels of gray in the image. In
MATLAB, histogram can calculated and displayed with a function imhist()

CODE:
%Redue to indexed color
[img_indexed, map]=rgb2ind(img,8);
imshow(img_indexed,map)
figure
imhist(img_indexed,map) %calculate and display the histogram

HISTOGRAM EQUALIZATION:

Histogram equalization is an operation of an image so that the number of pixels is approximately equal
for all histogram levels. In MATLAB, histogram can be equalized with the function histeq():

The idea behind Histogram Equalization is that we try to evenly distribute the occurrence of pixel
intensities so that the entire range of intensities is used more fully. We are trying to give each pixel
intensity equal opportunity; thus equalization. Especially for images with a wide range of values with
detail clustered around a few intensities, histogram will improve the contrast in image.

CODE:

img=imread(‘filename.fmt’); %read the image


subplot(221),
imshow(img)
img2=rgb2gray(img); %convert it to gray scale
suplot(222)
imshow(img2)
imgeq=histeq(img2) %equalize the histogram
subplot(223)
imhsow(imgeq)
subplot(224)
imhist(imgeq)

POST LAB TASK:

1. Read an Image and convert at least three different image types


2. Read any image and display their histograms.
3. Read any image and display their histogram equalization.
INSTITUTE OF BIOMEDICAL ENGINEERING & TECHNOLOGY LIAQUAT UNIVERSITY OF
MEDICAL & HEALTH SCIENCES JAMSHORO

Instructions:

 Please complete your lab reports neatly.


 All code must be commented appropriately and included in the file submitted.
 Handouts are required to be submitted by the next lab.
 Make sure your handout contains all the required information and that the file is named
correctly.

You might also like