Solution of a ROI filter types Matlab problem 4 4grade Mechatronics students!
Solved Problem: Write Matlab script to define a ROI on an input gray scale image, then enable the selection of filter types available with user control to keep selecting or not!
(The Output layout is like the figure below:)
%********************************************
%* ROI Filter Types for Gray images! *
%* Program name: ImageProEx33 *
%********************************************
close all
a = 'Y';
disp ('This is an example of Gray image ROI (Type) filter!');
disp ('==============================================');
clc
A = input ('Enter Gray level image file name: ','s');
I = imread(A);
I =rgb2gray(I);
% Hint: use the following Polygon Vertex coordinates for Coins ex. only!
% Columns: 222 272 300 270 221 194
% Rows : 21 21 75 121 121 75
N = input ('Enter No. of Polygon vertices: ');
for i=1:N
c(i) = input('Column: ');
r(i) = input('Row : ');
end
while (a=='Y') || (a=='y')
close all
% Using different types of available ROI filters
t = input ('Enter Filter No.(1-9): ');
BW = roipoly(I,c,r);
switch t
case 1
H = fspecial('average');
f = 'average';
case 2
H = fspecial('disk');
f = 'disk';
case 3
H = fspecial('gaussian');
f = 'gaussian';
case 4
H = fspecial('laplacian');
f = 'laplacian';
case 5
H = fspecial('log');
f = 'log';
case 6
H = fspecial('motion');
f = 'motion';
case 7
H = fspecial('prewitt');
f = 'prewitt';
case 8
H = fspecial('sobel');
f = 'sobel';
case 9
H = fspecial('unsharp');
f = 'unsharp';
otherwise
disp('Unknown Filter Type!');
end
J = roifilt2(H,I,BW);
subplot (1,2,1); imshow(I),title ('Original image');
subplot (1,2,2); imshow(J),title ({f,' Filtered image!'});
a = input ('Another try (Y/N)? ','s');
close all
end
(The Output layout is like the figure below:)
%********************************************
%* ROI Filter Types for Gray images! *
%* Program name: ImageProEx33 *
%********************************************
close all
a = 'Y';
disp ('This is an example of Gray image ROI (Type) filter!');
disp ('==============================================');
clc
A = input ('Enter Gray level image file name: ','s');
I = imread(A);
I =rgb2gray(I);
% Hint: use the following Polygon Vertex coordinates for Coins ex. only!
% Columns: 222 272 300 270 221 194
% Rows : 21 21 75 121 121 75
N = input ('Enter No. of Polygon vertices: ');
for i=1:N
c(i) = input('Column: ');
r(i) = input('Row : ');
end
while (a=='Y') || (a=='y')
close all
% Using different types of available ROI filters
t = input ('Enter Filter No.(1-9): ');
BW = roipoly(I,c,r);
switch t
case 1
H = fspecial('average');
f = 'average';
case 2
H = fspecial('disk');
f = 'disk';
case 3
H = fspecial('gaussian');
f = 'gaussian';
case 4
H = fspecial('laplacian');
f = 'laplacian';
case 5
H = fspecial('log');
f = 'log';
case 6
H = fspecial('motion');
f = 'motion';
case 7
H = fspecial('prewitt');
f = 'prewitt';
case 8
H = fspecial('sobel');
f = 'sobel';
case 9
H = fspecial('unsharp');
f = 'unsharp';
otherwise
disp('Unknown Filter Type!');
end
J = roifilt2(H,I,BW);
subplot (1,2,1); imshow(I),title ('Original image');
subplot (1,2,2); imshow(J),title ({f,' Filtered image!'});
a = input ('Another try (Y/N)? ','s');
close all
end


