MATLAB: I have plotted a image using imshow(Image). Now I placed “hold on” command. I have drawn the boundaries of each object in the image as given in code below. How to capture the new image with boundaries drawn in the plot into an array of pixels ?

digital image processingimage acquisitionimage analysisimage processingplot

[B,L,N] = bwboundaries(Image);
imshow(Image); hold on;
for k=1:length(B),
boundary = B{k};
if(k > N)
plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);
else
plot(boundary(:,2),boundary(:,1),'r','LineWidth',2);
end
end

Best Answer

  • Just assign them to an image in a loop inside the loop:
    for k=1:length(B)
    boundary = B{k};
    for k = 1 : size(boundary, 1)
    x = boundary(:,2); % Column
    y = boundary(:,1); % Row
    boundaryImage(y, x) = 255;
    end
    end