필터 지우기
필터 지우기

How to draw free-hand sketches using imfreehand ?

조회 수: 2 (최근 30일)
Avi Pal
Avi Pal 2012년 4월 4일
댓글: Image Analyst 2024년 6월 16일
I have to take as input hand drawn sketches ... I have tried using imfreehand() but it completes the figures itself.
I also tried the solution provided by Doug Schwarz in http://www.mathworks.in/matlabcentral/newsreader/view_thread/30168#75552 where he coded the following :
function sketch(cmd)
if nargin == 0
cmd = 'init';
end
switch cmd
case 'init'
fig = figure('DoubleBuffer','on','back','off');
info.ax = axes('XLim',[0 1],'YLim',[0 1]);
info.drawing = [];
info.x = [];
info.y = [];
set(fig,'UserData',info,...
'WindowButtonDownFcn',[mfilename,' down'])
case 'down'
myname = mfilename;
fig = gcbf;
info = get(fig,'UserData');
curpos = get(info.ax,'CurrentPoint');
info.x = curpos(1,1);
info.y = curpos(1,2);
info.drawing = line(info.x,info.y,'Color','k');
set(fig,'UserData',info,...
'WindowButtonMotionFcn',[myname,' move'],...
'WindowButtonUpFcn',[myname,' up'])
case 'move'
fig = gcbf;
info = get(fig,'UserData');
curpos = get(info.ax,'CurrentPoint');
info.x = [info.x;curpos(1,1)];
info.y = [info.y;curpos(1,2)];
set(info.drawing,'XData',info.x,'YData',info.y)
set(fig,'UserData',info)
case 'up'
fig = gcbf;
set(fig,'WindowButtonMotionFcn','',...
'WindowButtonUpFcn','')
end
But I am not able to save the sketch being drawn or access it ..
Please help ...

답변 (2개)

Walter Roberson
Walter Roberson 2012년 4월 4일
After the sketch use
info = get(gcf, 'Userdata')
The result will be a structure with .x and .y coordinate lists.
  댓글 수: 1
Avi Pal
Avi Pal 2012년 4월 8일
Sir, can you please elaborate a little; how can use info ? or if can save the image it will also do .

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2012년 4월 8일
If you want to use imfreehand to get x,y coordinates, you can do that. Here's s snippet from my demo:
hFH = imfreehand();
% Create a binary image ("mask") from the ROI object.
binaryImage = hFH.createMask();
% Just for demo purposes, get the x,y coordinates.
% We don't use them though in this demo.
xy = hFH.getPosition;
  댓글 수: 2
Avi Pal
Avi Pal 2012년 4월 8일
After drawing the sketch, i have to convex hull on it, so how can access the image in it ?
Image Analyst
Image Analyst 2024년 6월 16일
You can use convhull on the (x,y) coordinates.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by