free draw in gui

9 Ansichten (letzte 30 Tage)
armeen
armeen am 28 Apr. 2013
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..?

Akzeptierte Antwort

Image Analyst
Image Analyst am 28 Apr. 2013
Bearbeitet: Image Analyst am 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 Kommentare
Image Analyst
Image Analyst am 1 Mai 2013
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 am 11 Mai 2013
i had try run your code on matlab 2012...its working...tq fo ur help....=)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by