Prev: How to set input - outup data in Parameter Estimation
Next: Real Time Data Acquisition - Why doesn't it stop?
From: Corey Kelly on 9 Jul 2010 11:48 I have multiple ROI's selected in my GUI using imEllipse. I'd like to somehow have them labelled to differentiate one from another. I know that imPoint has the setString property which creates a text label, but this property doesn't seem available for other ROIs (rect, ellipse.) Is there a straightforward way to create such a label? The best idea I have so far is to create an invisible impoint along with each imellipse, so that its label can be used. This will, however cause me a world of trouble, as my ROIs are resizable, and need to be easily moved. I could construct position-based callbacks to keep the impoint in the right place, but that's a pain! Any advice would be appreciated.
From: Matthew Whitaker on 9 Jul 2010 13:11 "Corey Kelly" <ckelly01(a)uoguelph.ca> wrote in message <i17gbk$jb9$1(a)fred.mathworks.com>... > I have multiple ROI's selected in my GUI using imEllipse. I'd like to somehow have them labelled to differentiate one from another. I know that imPoint has the setString property which creates a text label, but this property doesn't seem available for other ROIs (rect, ellipse.) Is there a straightforward way to create such a label? > The best idea I have so far is to create an invisible impoint along with each imellipse, so that its label can be used. This will, however cause me a world of trouble, as my ROIs are resizable, and need to be easily moved. I could construct position-based callbacks to keep the impoint in the right place, but that's a pain! > > Any advice would be appreciated. Hi Corey, The elegant way to do this is to subclass imellipse to include this functionality. So quick and dirty: classdef imellipselabel < imellipse methods %Constructor function obj = imellipselabel(varargin) obj = obj(a)imellipse(varargin{:}); end %imellipselabel function setString(obj,str,textOp) if nargin < 3 textOp = struct([]); end %if %check to see if there is already a text label existLabel = findobj(obj.h_group,'Type','text','Tag','label'); if isempty(existLabel) existLabel = text('Parent',obj.h_group,... 'Position',obj.getTextPos,... 'String',str,... 'HorizontalAlignment','left',... 'BackgroundColor','w',... 'Tag','label'); obj.addNewPositionCallback(@obj.textPosition_Callback); else %update the existing tag set(existLabel(1),'String',str); end %if if ~isempty(textOp) set(existLabel(1),textOp); end %if end %setString end %methods methods (Access = private) function textPosition_Callback(obj,varargin) existLabel = findobj(obj.h_group,'Type','text','Tag','label'); if ~isempty(existLabel) set(existLabel(1),'Position',obj.getTextPos); end %if end %setPosition function textPos = getTextPos(obj) pos =obj.getVertices; [maxSum,maxIdx] = max(sum(pos,2)); %#ok if you have up to date version use ~ textPos = pos(maxIdx,:)+5; end %getTextPos end %private methos end %imellipse %test above op.BackgroundColor = 'g'; figure, imshow('cameraman.tif'); h = imellipselabel(gca, [10 10 100 100]); h.setString('test',op); Hope this helps Matt W
From: Corey Kelly on 9 Jul 2010 14:44
"Matthew Whitaker" <mattlwhitaker(a)REMOVEgmail.com> wrote in message <i17l78$fua$1(a)fred.mathworks.com>... > "Corey Kelly" <ckelly01(a)uoguelph.ca> wrote in message <i17gbk$jb9$1(a)fred.mathworks.com>... > > I have multiple ROI's selected in my GUI using imEllipse. I'd like to somehow have them labelled to differentiate one from another. I know that imPoint has the setString property which creates a text label, but this property doesn't seem available for other ROIs (rect, ellipse.) Is there a straightforward way to create such a label? > > The best idea I have so far is to create an invisible impoint along with each imellipse, so that its label can be used. This will, however cause me a world of trouble, as my ROIs are resizable, and need to be easily moved. I could construct position-based callbacks to keep the impoint in the right place, but that's a pain! > > > > Any advice would be appreciated. > > Hi Corey, > The elegant way to do this is to subclass imellipse to include this functionality. > > So quick and dirty: > > classdef imellipselabel < imellipse > > methods > %Constructor > function obj = imellipselabel(varargin) > obj = obj(a)imellipse(varargin{:}); > end %imellipselabel > > function setString(obj,str,textOp) > if nargin < 3 > textOp = struct([]); > end %if > %check to see if there is already a text label > existLabel = findobj(obj.h_group,'Type','text','Tag','label'); > > if isempty(existLabel) > existLabel = text('Parent',obj.h_group,... > 'Position',obj.getTextPos,... > 'String',str,... > 'HorizontalAlignment','left',... > 'BackgroundColor','w',... > 'Tag','label'); > > obj.addNewPositionCallback(@obj.textPosition_Callback); > else > %update the existing tag > set(existLabel(1),'String',str); > > end %if > > if ~isempty(textOp) > set(existLabel(1),textOp); > end %if > > > end %setString > > > end %methods > > methods (Access = private) > > function textPosition_Callback(obj,varargin) > existLabel = findobj(obj.h_group,'Type','text','Tag','label'); > if ~isempty(existLabel) > set(existLabel(1),'Position',obj.getTextPos); > end %if > end %setPosition > > function textPos = getTextPos(obj) > pos =obj.getVertices; > [maxSum,maxIdx] = max(sum(pos,2)); %#ok if you have up to date version use ~ > textPos = pos(maxIdx,:)+5; > end %getTextPos > end %private methos > end %imellipse > > > %test above > > op.BackgroundColor = 'g'; > figure, imshow('cameraman.tif'); > h = imellipselabel(gca, [10 10 100 100]); > h.setString('test',op); > > > Hope this helps > > Matt W This is perfect! Thanks a lot. |