Previewing a selection area on an image in a gui - possibly based off freehanddraw.m?

1 Ansicht (letzte 30 Tage)
My entire goal of this project is to make an "eraser" of sorts, where you can select that you want to erase, and then click where you want to erase, erase (turn pixels "underneath" white), and then click when you want to be done erasing. I stumbled across Brett Shoelson's freehanddraw mfile on the file exchange which draws a line when you click and stops drawing when you click again and gives you the points that you drew over. (The code is below)
What I have so far:
-A gui that allows you to load an image
-A button that calls the freehanddraw script
-A slider to determine the eraser size
-Some code that given the points you drew over will make all the pixels in the eraser size white.
What I want/Am missing:
-The ability to preview what I am going to erase, instead of making a 1 pixel thick line of where I have gone, I want to it to highlight with the thickness of the eraser as given by the slider. Selecting the pixels isn't my trouble, its getting the image to update mid draw so I know what's going to be erased and what is not.
*Specifically: *
I am looking for a way to update the image quickly mid-draw and have it refreshed throughout.
Where I think would be helpful to look but I am confused:
In the wbmfcn function (second to the bottom) this is the button move function
Thanks for any help!
if true
% function [lineobj,xs,ys] = freehanddraw(varargin)
% % [LINEOBJ,XS,YS] = FREEHANDDRAW(ax_handle,line_options)
% %
% % Draw a smooth freehand line object on the current axis (default),
% % or on the axis specified by handle in the first input argument.
% % Left-click to begin drawing, right-click to terminate, or double-click
% % to close contour and terminate.
% %
% %
% % INPUT ARGUMENTS: First: axis handle (optional)
% % Additional: valid line property/value pairs
% %
% % OUTPUT ARGUMENTS: 1) Handle to line object
% % 2) x-data
% % 3) y-data
% % (Note that output args 2 and 3 can also be extracted from the first output
% % argument.)
% %
% % Ex: [myobj,xs,ys] = freehanddraw(gca,'color','r','linewidth',3);
% % freehanddraw('linestyle','--');
% %
% % Written by Brett Shoelson, PhD
% % shoelson@helix.nih.gov
% % 3/29/05
% % Modified:
% % 10/05/05: Now allows double-click closing of contour
%
% axdef = 0;
% if nargin ~= 0 && ishandle(varargin{1})
% try
% axes(varargin{1});
% axdef = 1;
% catch
% error('If the initial input argument is a handle, it must be to a valid axis.');
% end
% end
%
%
% %Get current figure and axis parameters
% oldvals = get(gcf);
% oldhold = ishold(gca);
%
% hold on;
%
% set(gcf,'Pointer','crosshair','doublebuffer','on');
%
% %Get the initial point
% [xs,ys,zs] = ginput(1);
%
% %Create and store line object
% if axdef
% lineobj = line(xs,ys,'tag','tmpregsel',varargin{2:end});
% else
% lineobj = line(xs,ys,'tag','tmpregsel',varargin{:});
% end
% setappdata(gcf,'lineobj',lineobj);
%
% %Modify wbmf of current figure to update lineobject on mouse motion
% set(gcf,'windowbuttonmotionfcn',@wbmfcn);
% set(gcf,'windowbuttondownfcn',@wbdfcn);
% %Wait for right-click or double-click
% while ~strcmp(get(gcf,'SelectionType'),'alt') && ~strcmp(get(gcf,'SelectionType'),'open')
% drawnow;
% end
%
% %Extract xyz data from line object for return in output variables
% %(Also retrievable from first output argument)
% if nargout > 1
% xs = get(getappdata(gcf,'lineobj'),'xdata')';
% end
% if nargout > 2
% ys = get(getappdata(gcf,'lineobj'),'ydata')';
% end
%
% %Clear temporary variables from base workspace
% evalin('caller','clear tmpx tmpy tmpz done gca lineobj');
%
% %Reset figure parameters
% set(gcf,'Pointer',oldvals.Pointer,...
% 'windowbuttonmotionfcn',oldvals.WindowButtonMotionFcn,...
% 'windowbuttondownfcn',oldvals.WindowButtonDownFcn);
% %'doublebuffer',oldvals.DoubleBuffer);
%
%
% if isfield(oldvals, 'DoubleBuffer')
% set(gcf,'doublebuffer',oldvals.DoubleBuffer);
% end
%
% %Reset hold value of the axis
% if ~oldhold, hold off; end
%
%
%
% function wbmfcn(varargin)
%
% lineobj = getappdata(gcf,'lineobj');
% if strcmp(get(gcf,'selectiontype'),'normal');
% tmpx = get(lineobj,'xdata');
% tmpy = get(lineobj,'ydata');
% a=get(gca,'currentpoint');
% set(lineobj,'xdata',[tmpx,a(1,1)],'ydata',[tmpy,a(1,2)]);
% drawnow;
% else
% setappdata(gcf,'lineobj',lineobj);
% end
%
% function wbdfcn(varargin)
%
% lineobj = getappdata(gcf,'lineobj');
% if strcmp(get(gcf,'selectiontype'),'open')
% tmpx = get(lineobj,'xdata');
% tmpy = get(lineobj,'ydata');
% a=get(gca,'currentpoint');
% set(lineobj,'xdata',[tmpx,tmpx(1)],'ydata',[tmpy,tmpy(1)]);
% setappdata(gcf,'lineobj',lineobj);
% drawnow;
% end
% return
end

Akzeptierte Antwort

Shaun VanWeelden
Shaun VanWeelden am 22 Dez. 2012
The answer was to use "Patch" instead of "line" and patch together circles on all the points, it works extremely well now. If anybody else wants the code, just contact me, otherwise I will probably be putting it on the file exchange when I am done with the project.
Thanks for the help ImageAnalyst!

Weitere Antworten (1)

Image Analyst
Image Analyst am 21 Dez. 2012
There is no such capability in MATLAB that I'm aware of. Essentially you'd have to write your own imfreehand() where you actually erase or paint over a wide swath of pixels instead of laying down a thin line. Perhaps you can tie into the mousemove event.
  1 Kommentar
Shaun VanWeelden
Shaun VanWeelden am 22 Dez. 2012
I am looking to write my own sort of, I do not want to select the area as imfreehand does, merely select a swath every where the cursor goes.., it seems the lineobj might be a good starting point, but I have never seen it used that way and do not quite understand it yet.
Thanks, Shaun

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images 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