how to extract the portion of an image specified by an edge in matlab
조회 수: 1 (최근 30일)
이전 댓글 표시
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);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161288/image.jpeg)
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!