필터 지우기
필터 지우기

how to extract the portion of an image specified by an edge in matlab

조회 수: 1 (최근 30일)
sudarshan r
sudarshan r 2017년 3월 3일
편집: Walter Roberson 2017년 3월 3일
i have write the code to convert the image into three different colors and i applied an edge filter, i added the edge and original image now i need to get only leaf portion of the image
my code is
clc
close all;
clear all;
[fname path]=uigetfile('*.*','insert the pic');
a=imread(fname);
figure(1);
imshow(a)
w=0;d=0;z=0;
b=ones(size(a,1),size(a,2),size(a,3));
for i=1:size(a,1)
for j=1:size(a,2)
for k=1:size(a,3)
if a(i,j,2)>a(i,j,1)+5 && a(i,j,2)>a(i,j,3)+5
b(i,j,1)=255;
b(i,j,2)=0;
b(i,j,3)=0;
end
end
end
end
figure(2);
imshow(uint8(b));
for i=1:size(a,1)
for j=1:size(a,2)
for k=1:size(a,3)
if a(i,j,1)>170 || a(i,j,2)>170|| a(i,j,3)>200-30
b(i,j,1)=0;
b(i,j,2)=255;
b(i,j,3)=0;
end
end
end
end
figure(3);
imshow(uint8(b));
% se=strel('line',1,0);
% im1=imerode(b,se);
% figure(4);
% imshow(im1);
%
%
% for i=1:size(a,1)
% for j=1:size(a,2)
% for k=1:size(a,3)
% if im1(i,j,1)==0 && im1(i,j,2)==0 && im1(i,j,3)==0
% b(i,j,1)=255;
% b(i,j,2)=0;
% b(i,j,3)=0;
%
% end
%
% end
% end
% end
% figure(5);
% imshow(uint8(b));
g=rgb2gray(uint8(b));
s=edge(g,'sobel');
figure(4);
imshow(s);
gd=im2double(g);
od=im2double(a);
re=bsxfun(@minus,od,gd);
figure(5);
imshow(re);
s=imcrop(re);
figure(6);
imshow(s);

답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by