Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
sudarshan r
sudarshan r le 3 Mar 2017
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);

Réponses (0)

Catégories

En savoir plus sur Image Filtering and Enhancement dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by