現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
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..?
採用された回答
Image Analyst
2013 年 4 月 28 日
編集済み: Image Analyst
2013 年 4 月 28 日
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 件のコメント
armeen
2013 年 4 月 30 日
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
2013 年 4 月 30 日
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
2013 年 4 月 30 日
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();
Image Analyst
2013 年 5 月 1 日
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
2013 年 5 月 11 日
i had try run your code on matlab 2012...its working...tq fo ur help....=)
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Interactive Control and Callbacks についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
