free draw in gui

hello.. i want to a simple gui that contain a plain space so that i can sign on that plain . then i also want to put a push button in that gui so that i can save the figure of my sign.
i try to use the code in http://www.mathworks.com/matlabcentral/fileexchange/7347 and it work perfectly. i actually want to place the figure of free draw into the gui...
my question is that possible for me to use the axes gui as the place where the plain figure to appear..? (sorry for my English)
can anyone help me..?

 Accepted Answer

Image Analyst
Image Analyst on 28 Apr 2013
Edited: Image Analyst on 28 Apr 2013
Yes, it is. Go ahead and set the active axes with
axes(handles.axes2); % Assuming you want axes2 to be the one you draw in.
[x, y] = imfreehand().
Here's a standalone demo:
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 16;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
message = sprintf('Sign your name.\nLeft click and hold to begin drawing.\nSimply lift the mouse button to finish');
uiwait(msgbox(message));
% User signs name here.
hFH = imfreehand();
% Get the xy coordinates of where they drew.
xy = hFH.getPosition
% get rid of imfreehand remnant.
delete(hFH);
% Overlay what they drew onto the image.
hold on; % Keep image, and direction of y axis.
xCoordinates = xy(:, 1);
yCoordinates = xy(:, 2);
plot(xCoordinates, yCoordinates, 'ro-', 'LineWidth', 2);
caption = sprintf('Original Grayscale Image.\nPoints may not lie on adjacent pixels, depends on your speed of drawing!', 'FontSize', fontSize);
title(caption, 'FontSize', fontSize);
% Ask user if they want to burn the line into the image.
promptMessage = sprintf('Do you want to burn the line into the image?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if strcmpi(button, 'Cancel')
return;
end
cla;
hold off;
for k = 1 : length(xCoordinates)
row = int32(yCoordinates(k));
column = int32(xCoordinates(k));
grayImage(row, column) = 255;
end
imshow(grayImage, []);
axis on;
caption = sprintf('Grayscale Image with Burned In Curve.\nPoints may not lie on adjacent pixels, depends on your speed of drawing!', 'FontSize', fontSize);
title(caption, 'FontSize', fontSize);

5 Comments

i sorry sir... i am very new on this matlab..n i really don't get what u telling me..=(
ok let start over again...i actually want to create a simple program that can be use as signature input..the signature that need to be verify.. during review on the file exchange i got a new free hand drawing which the code is like this..:
%% sketch on the plain
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]);
axis off
info.drawing = [];
info.x = [];
info.y = [];
info.t =[];
set(fig,'UserData',info,...
'WindowButtonDownFcn',[mfilename,' down'])
case 'down'
tic;
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.e = curpos(1,1); %to read x coordinate in single
info.f = curpos(1,2); %to read y coordinate in single
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'
toc;
fig = gcbf;
set(fig,'WindowButtonMotionFcn','',...
'WindowButtonUpFcn','')
drawnow; pause(.1)
info = get(gcf, 'Userdata')
end
i run with matlab R2007b...if u run this code u will get a plain figure where u can draw freely on that figure.. my problem now is i don't know how to place this code into the gui so that i can freely sign on gui.
and if possible, i also want to place a push button in the gui so that i can save the sign figure as a image in a folder.
hmm...hope u get what my problem..
regard
Image Analyst
Image Analyst on 30 Apr 2013
Your code essentially does nothing, so I'm not at all surprised it doesn't work. However, I'm still baffled as to why my code that lets you draw your signature onto an image, and save the image, is not what you want.
armeen
armeen on 30 Apr 2013
hmmm....i really don't know...its already 6.30am here... i successfully run my code...
but when i try to directly run ur standalone demo..matlab came with this error...
??? Error using ==> iptchecknargin at 57 Function IMFREEHAND expected at least 1 input argument but was called instead with 0 input arguments.
Error in ==> roiParseInputs at 29 iptchecknargin(low,high,nargin_client,client_name);
Error in ==> imfreehand at 166 [commonArgs,specificArgs] = roiParseInputs(1,5,varargin,mfilename,{'Closed'});
Error in ==> Untitled at 31 hFH = imfreehand();
It doesn't require any arguments, as the help and examples in the help show. Though you can call it passing gca as the input if you want. put
whos imfreehand
right before to see what it says. Maybe you have a second one somewhere that's overwriting it.
armeen
armeen on 11 May 2013
i had try run your code on matlab 2012...its working...tq fo ur help....=)

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!