Saving image from figure with freehand draw

5 visualizaciones (últimos 30 días)
awezmm
awezmm el 26 de Jul. de 2017
Respondida: Image Analyst el 2 de Ag. de 2017
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.

Respuesta aceptada

Image Analyst
Image Analyst el 2 de Ag. de 2017

Más respuestas (1)

Walter Roberson
Walter Roberson el 26 de Jul. de 2017
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 comentarios
Walter Roberson
Walter Roberson el 27 de Jul. de 2017
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 el 1 de Ag. de 2017
It doesn't work. Seems like nothing was burned

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by