Saving image from figure with freehand draw
1 次查看(过去 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.
0 个评论
采纳的回答
Image Analyst
2017-8-2
After imfreehand(), call plot() to plot the drawn curve on the image, then call export_fig() to save the image and graphical overlay into a PNG image on disk.
0 个评论
更多回答(1 个)
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
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"
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!