Saving image from figure with freehand draw
2 ビュー (過去 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!