onclick - get information from click on any object in the image in matlab -


i work on image segmentation based on color object.. need user click value on object in order use information (click value)in process. how can value in matlab. 1 can me please.

regards

i'm not sure if answers question, plot objects (i.e. lines, patches, images, etc.) have buttondownfcn callback execute when press mouse button while pointer on object.

here's simple example (using nested functions , function handles) of how use buttondownfcn callbacks information objects selected. first, save function in m-file:

function colorfcn = colored_patches    selectedcolor = [1 0 0];  %# default selected color    figure;                                  %# create new figure   axes;                                    %# create new axes   patch([0 0 1 1],[0 1 1 0],'r',...        %# plot red box         'buttondownfcn',@patch_callback);   hold on;                                 %# add existing plot   patch([2 2 4 4],[1 2 2 1],'g',...        %# plot green box         'buttondownfcn',@patch_callback);   patch([1 1 2 2],[3 4 4 3],'b',...        %# plot blue box         'buttondownfcn',@patch_callback);   axis equal;                              %# set axis scaling    colorfcn = @get_color;  %# return function handle get_color  %#---nested functions below---    function patch_callback(src,event)     selectedcolor = get(src,'facecolor');  %# set selected color                                            %#   color of patch clicked on   end    function currentcolor = get_color     currentcolor = selectedcolor;          %# return last color selected   end  end 

next, run above code , save returned function handle in variable:

colorfcn = colored_patches; 

this create figure 3 colored boxes, so:

alt text

now, when click mouse on 1 of colored boxes, output colorfcn change:

%# click red box, call colorfcn >> colorfcn() ans =      1     0     0  %# returns red  %# click blue box, call colorfcn >> colorfcn() ans =      0     0     1  %# returns blue  %# click green box, call colorfcn >> colorfcn() ans =      0     1     0  %# returns green 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -