Saving image from figure with freehand draw

6 次查看(过去 30 天)
I read an image, open a figure, and imshow that image on the figure. Then I imfreehand on that figure. How do I automatically save that resultant image in the figure that has the freehand drawing on it??? Do I need to "burn" the freehand drawing into the image or can is there a function that saves everything displaying on a figure. I want to save it to a folder in my computer.

采纳的回答

Image Analyst
Image Analyst 2017-8-2

更多回答(1 个)

Walter Roberson
Walter Roberson 2017-7-26
You could use something like the shape inserter from Vision Toolbox. Or you could grab the vertices and poly2mask and find the boundary and use the boundary indices to scribble in the image.
It is possible to do a screen capture, but that might well be at a different resolution than your original image; is that acceptable, or do you need it the original resolution?
  3 个评论
Walter Roberson
Walter Roberson 2017-7-27
h = imfreehand(....);
Then when ready
lineRGB = [192 16 45]; %adjust the line color as appropriate
%freehand into mask enclosing entire area
freehand_pos = getPosition(h);
freehand_mask = poly2mask(freehand_pos(:,1), freehand_pos(:,2), size(YourImage,1), size(YourImage,2) );
%get boundary of mask
B = bwboundaries(freehand_mask);
P = B{1};
%convert boundary to linear indices
Pind = sub2ind(size(YourImage), P);
%burn into a copy, not original
newImage = YourImage;
%start burning
slicesize = size(YourImage,1) * size(YourImage,2);
for K = 1 : size(newImage, 3)
newImage( Pind + (K-1) * slicesize ) = lineRGB(K);
end
The Pind + (K-1) * slicesize part is computing linear indices for each color plane.
It would not entirely surprise me if the boundaries generated this way tend to be inside the line you drew. If so then I might try something like
SE = strel('square',2);
Pind = find(imtophat(freehand_mask, SE));
replacing the block at "get boundary of mask"
awezmm
awezmm 2017-8-1
It doesn't work. Seems like nothing was burned

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by