0% found this document useful (0 votes)
31 views5 pages

Matlab Programs: Program No 1

The document contains 10 MATLAB programs. Program 1 loads an image, performs histogram equalization, and saves the output. Programs 2-7 perform image processing tasks like background removal, thresholding, and component labeling on rice grain images. Program 8 displays a magic square image on a non-uniform grid. Program 9 creates and displays an RGB image from the jet colormap. Program 10 reads an image and displays its bit depth.

Uploaded by

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

Matlab Programs: Program No 1

The document contains 10 MATLAB programs. Program 1 loads an image, performs histogram equalization, and saves the output. Programs 2-7 perform image processing tasks like background removal, thresholding, and component labeling on rice grain images. Program 8 displays a magic square image on a non-uniform grid. Program 9 creates and displays an RGB image from the jet colormap. Program 10 reads an image and displays its bit depth.

Uploaded by

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

MATLAB PROGRAMS

PROGRAM NO 1 :
clear
close all
I = imread('pout.tif');
imshow(I)
figure
imhist(I)
I2 = histeq(I);
figure
imshow(I2)
figure
imhist(I2)
imwrite (I2, 'pout2.png');
imfinfo('pout2.png')
PROGRAM NO 2 :
clear
close all
I = imread('rice.png');
imshow(I)
background = imopen(I,strel('disk',15));
figure
surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
PROGRAM NO 3 :
clear
close all
I = imread('rice.png');
imshow(I)
background = imopen(I,strel('disk',15));
figure
surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
I2 = I - background;
imshow(I2)

PROGRAM NO 4 :
clear
close all
I = imread('rice.png');
imshow(I)
background = imopen(I,strel('disk',15));
figure
surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
I2 = I - background;
imshow(I2)
I3 = imadjust(I2);
imshow(I3);
level = graythresh(I3);
bw = im2bw(I3,level);
bw = bwareaopen(bw, 50);
imshow(bw)
PROGRAM NO 5 :
clear
close all
I = imread('rice.png');
imshow(I)
background = imopen(I,strel('disk',15));
figure
surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
I2 = I - background;
imshow(I2)
I3 = imadjust(I2);
imshow(I3);
level = graythresh(I3);
bw = im2bw(I3,level);

bw = bwareaopen(bw, 100);
imshow(bw)
cc = bwconncomp(bw, 4)
cc.NumObjects
grain = false(size(bw));
grain(cc.PixelIdxList{50}) = true;
imshow(grain);
PROGRAM NO 6 :
clear
close all
I = imread('rice.png');
imshow(I)
background = imopen(I,strel('disk',15));
figure
surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
I2 = I - background;
imshow(I2)
I3 = imadjust(I2);
imshow(I3);
level = graythresh(I3);
bw = im2bw(I3,level);
bw = bwareaopen(bw, 50);
imshow(bw)
cc = bwconncomp(bw, 4)
cc.NumObjects
grain = false(size(bw));
grain(cc.PixelIdxList{50}) = true;
imshow(grain);
labeled = labelmatrix(cc);
RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle');
imshow(RGB_label)

PROGRAM NO 7 :
clear
close all
I = imread('rice.png');
imshow(I)
background = imopen(I,strel('disk',15));
figure
surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
I2 = I - background;
imshow(I2)
I3 = imadjust(I2);
imshow(I3);
level = graythresh(I3);
bw = im2bw(I3,level);
bw = bwareaopen(bw, 50);
imshow(bw)
cc = bwconncomp(bw, 4)
cc.NumObjects
grain = false(size(bw));
grain(cc.PixelIdxList{50}) = true;
imshow(grain);
labeled = labelmatrix(cc);
RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle');
imshow(RGB_label)
graindata = regionprops(cc, 'basic')
graindata(50).Area
grain_areas = [graindata.Area];
[min_area, idx] = min(grain_areas)
grain = false(size(bw));
grain(cc.PixelIdxList{idx}) = true;
imshow(grain);
nbins = 20;
figure, hist(grain_areas, nbins)
title('Histogram of Rice Grain Area');

PROGRAM NO

8 :

clear
close all
A = magic(5);
x = [19.5 23.5];
y = [8.0 12.0];
image(A,'XData',x,'YData',y), axis image, colormap(jet(25))
I = [1 2 ; 3 4]
R = imref2d(size(I),4,2)

PROGRAM NO

9 :

clear
close all
RGB=reshape(ones(64,1)*reshape(jet(64),1,192),[64,64,3]);
R=RGB(:,:,1);
G=RGB(:,:,2);
B=RGB(:,:,3);
imshow(R)
figure, imshow(G)
figure, imshow(B)
figure, imshow(RGB)

PROGRAM NO 10 :
clear
close all
info = imfinfo('text.png');
info.BitDepth
BW = imread('text.png');

You might also like