I have plotted the boundaries of a binary image Ax in the code, Is there a way to use the boundary plot itself as the image for further processing?

1 次查看(过去 30 天)
if true
file= 'hemanths1.csv';
% read the csv file into an image
data=csvread(file,1,1);
[r,c]=size(data);
c=c-1;
kq=10; %thresholding variable
data1(1:r,1:c)=data(1:r,1:c);
data1=(data1-minfun(data1))/(maxfun(data1)-minfun(data1));
t=imhist(data1);
% histogram of the image is taken
[~,loc]=maxfun2(t);
smoothened=sgolayfilt(t(loc:end),3,45); % smothened the curve
smoothened=sgolayfilt(smoothened,3,45);
smoothened=sgolayfilt(smoothened,3,45);
smoothened=sgolayfilt(smoothened,3,45);
smoothened=sgolayfilt(smoothened,3,45);
smoothened=sgolayfilt(smoothened,3,45);
smoothened=sgolayfilt(smoothened,3,45);
smoothened=sgolayfilt(smoothened,3,45);
%smoothened=sgolayfilt(smoothened,3,45);
% divide the forward and backward pixels in the image
[~,g2]=findpeaks(-smoothened);
% remove the backward pixels and take the threshold
Ax=data1>(loc+g2(1)-kq)/256;
% remove smaller ojects
Ax=bwareaopen(Ax,10000);
bound=bwboundaries(Ax);
k=size(bound,1);
% what im doing is to select the blob with the highest circumference
check=zeros(k,1);
for i=1:k
check(i)=size(bound{i,1},1);
end
[~,indexofmax]=maxfun2(check);
B=bound{indexofmax,1};
new=B;
% seperate X and Y
x=new(:,2);
y=new(:,1);
windowWidth = 61;
polynomialOrder = 3;
% smooth them using sowitscky golay filter
X = sgolayfilt(x, polynomialOrder, windowWidth);
Y = sgolayfilt(y, polynomialOrder, windowWidth);
mat=[X,Y];
figure, imshow(Ax);
hold on
plot(X,Y, '-b','linewidth', 2);
end
I want to use the plot itself as my new image and discard the unnecessary peaks and the background image on which the plot is made. Please help

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by