Thread Subject: changing position of a image

Subject: changing position of a image

From: Rui Gomes

Date: 30 Nov, 2008 01:33:02

Message: 1 of 6

hi.

i am developing a matlab guide.
i have 3 images, 2 of then will never move,
the first is to collect points,
the second is a example image
and the third is the smallest and will move in the second image according with the points i want the user to click on the first image.

but and i do:

    pos_act =get(handles.axes3,'Position');
    set(handles.axes3,'Position',[590 214 pos_act(3) pos_act(4)]);

the third image dissipates.

what can i do?

thanks for the help

Subject: changing position of a image

From: Ryan Ollos

Date: 30 Nov, 2008 02:13:01

Message: 2 of 6

"Rui Gomes" <rpgomes84@gmail.com> wrote in message <ggsqge$hrt$1@fred.mathworks.com>...
> hi.
>
> i am developing a matlab guide.
> i have 3 images, 2 of then will never move,
> the first is to collect points,
> the second is a example image
> and the third is the smallest and will move in the second image according with the points i want the user to click on the first image.
>
> but and i do:
>
> pos_act =get(handles.axes3,'Position');
> set(handles.axes3,'Position',[590 214 pos_act(3) pos_act(4)]);
>
> the third image dissipates.
>
> what can i do?
>
> thanks for the help

I would suggest first checking the units property of your axes and figure. Assuming that isn't the problem, you might take a look at the solution someone provided me in this thread. I was trying to "stack" images:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/237542

Also, could you make image3 and image1 share the same axes? I think that would make the problem easier to manage.

Subject: changing position of a image

From: Rui Gomes

Date: 30 Nov, 2008 02:40:18

Message: 3 of 6


> I would suggest first checking the units property of your axes and figure. Assuming that isn't the problem, you might take a look at the solution someone provided me in this thread. I was trying to "stack" images:
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/237542
>
> Also, could you make image3 and image1 share the same axes? I think that would make the problem easier to manage.

im making some experiences
and when i put im guide .m file:

handles.redI = imread('red_spot.jpg');
pos_act =get(handles.axes3,'Position')
set(handles.axes3,'Position',[111 111 pos_act(3) pos_act(4)]);
image(handles.redI);
axis off;

my image dissipates, and the image that i had associate in handles.axes3 and to change position several times.

i don't know what to do, im to novice in matlab guide.
the image is only a red point that i want to put in front of the image that is in handles.axes2

thanks for the help.

Subject: changing position of a image

From: ImageAnalyst

Date: 30 Nov, 2008 03:15:10

Message: 4 of 6

On Nov 29, 9:40=A0pm, "Rui Gomes" <rpgome...@gmail.com> wrote:
> > I would suggest first checking the units property of your axes and figu=
re. =A0Assuming that isn't the problem, you might take a look at the soluti=
on someone provided me in this thread. =A0I was trying to "stack" images:
>
> >http://www.mathworks.com/matlabcentral/newsreader/view_thread/237542
>
> > Also, could you make image3 and image1 share the same axes? =A0I think =
that would make the problem easier to manage.
>
> im making some experiences
> and when i put im guide .m file:
>
> handles.redI =3D imread('red_spot.jpg');
> pos_act =3Dget(handles.axes3,'Position')
> set(handles.axes3,'Position',[111 111 pos_act(3) pos_act(4)]);
> image(handles.redI);
> axis off;
>
> my image dissipates, and the image that i had associate in handles.axes3 =
and to change position several times.
>
> i don't know what to do, im to novice in matlab guide.
> the image is only a red point that i want to put in front of the image th=
at is in handles.axes2
>
> thanks for the help.

Rui:
Use the "hold on" command. What happens is that when you display the
red dot, it replaces the image that was previously in the axes. If
you set hold on then I think it will retain the image and just place
the red dot on top of the existing image.
Regards,
ImageAnalyst
P.S. I think you mean "disappear" rather than dissipate.

Subject: changing position of a image

From: Ryan Ollos

Date: 30 Nov, 2008 07:55:07

Message: 5 of 6

"Rui Gomes" <rpgomes84@gmail.com> wrote in message <ggsuei$2u8$1@fred.mathworks.com>...
>
> im making some experiences
> and when i put im guide .m file:
>
> handles.redI = imread('red_spot.jpg');
> pos_act =get(handles.axes3,'Position')
> set(handles.axes3,'Position',[111 111 pos_act(3) pos_act(4)]);
> image(handles.redI);
> axis off;
>
> my image dissipates, and the image that i had associate in handles.axes3 and to change position several times.
>
> i don't know what to do, im to novice in matlab guide.
> the image is only a red point that i want to put in front of the image that is in handles.axes2

I think you need to put these 3 commands in the portion of your GUIDE code other than the Callback (such as CreateFcn for the axes).

handles.redI = imread('red_spot.jpg');
image(handles.redI);
axis off;

Then, in ButtonDownFcn for Axes 1 (assuming Axes 1 and 2 are the same size),

cursorPos = get(handles.axes1, 'CurrentPosition')
pos_act =get(handles.axes3,'Position')
set(handles.axes3,'Position',[111 111 pos_act(3) pos_act(4)]);

I think that covers the basic idea, but there is more too it than that, so I'll post an example code that you can run.

Subject: changing position of a image

From: Ryan Ollos

Date: 30 Nov, 2008 09:09:03

Message: 6 of 6

% This function hopefully implements what you want to do for the most part

function h = moveImageTest

h.figure = figure;

h.axes(1) = axes('Parent', h.figure, ...
    'Position', [0.05 0.1 0.4 0.4], ...
    'XTick', [], ...
    'YTick', [], ...
    'XColor', get(h.figure, 'Color'), ...
    'YColor', get(h.figure, 'Color'), ...
    'ButtonDownFcn', @axes_moveImage, ...
    'CreateFcn', {@axes_loadImage, 1});

h.axes(2) = axes('Parent', h.figure, ...
    'Position', [0.55 0.1 0.4 0.4], ...
    'XTick', [], ...
    'YTick', [], ...
    'XColor', get(h.figure, 'Color'), ...
    'YColor', get(h.figure, 'Color'), ...
    'CreateFcn', {@axes_loadImage, 2});

h.axes(3) = axes('Parent', h.figure, ...
    'Position', [0.75 0.25 0.025 0.025], ...
    'XTick', [], ...
    'YTick', [], ...
    'CreateFcn', @axes_loadImage3);

% Get handles saved in CreateFcn's
h2 = guidata(h.figure);
% Merge h and h2
fieldName = fieldnames(h2);
for i=1:length(h2)
    h.(fieldName{i}) = h2.(fieldName{i});
end

guidata(h.figure, h);


function axes_loadImage(hObject, eventdata, axesNum)

h = guidata(hObject);
axes(hObject);

I = imread('rice.png');

% Use low level function call for image so axes properties are not reset
h.image(axesNum) = image('CData', I);

% Set HitTest property to off so button clicks will be handled by the
% parent axes
set(h.image(axesNum), 'HitTest', 'off');

axis tight;

hf = ancestor(hObject, 'Figure');
guidata(hf, h);


function axes_loadImage3(hObject, eventdata)

h = guidata(hObject);
axes(hObject);

I = zeros(20,20,3); %small black square

% Use low level function call for image so axes properties are not reset
h.image(3) = image('CData', I);

axis tight;

hf = ancestor(hObject, 'Figure');
guidata(hf, h);


function axes_moveImage(hObject, eventdata)

h = guidata(hObject);

AxesXLim = get(hObject, 'XLim');
AxesYLim = get(hObject, 'YLim');
Axes2Pos = get(h.axes(2), 'Position');

% Cursor position is in axes data units
% Get cursor position in normalized units
CursorPosition = get(hObject, 'CurrentPoint'); %in axes data units
CursorPositionN = [CursorPosition(1, 1)/AxesXLim(2) CursorPosition(1, 2)/AxesYLim(2)];

% Use cursor position (within axes 1) to find same relative position in
% axes 2
Axes3Pos = get(h.axes(3), 'Position');
NewAxes3Pos(1:2) = CursorPositionN.*Axes2Pos(3:4) + Axes2Pos(1:2);
NewAxes3Pos(3:4) = Axes3Pos(3:4);

set(h.axes(3), 'Position', NewAxes3Pos);

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
image position ... Rui Gomes 29 Nov, 2008 21:45:07
guide image Rui Gomes 29 Nov, 2008 20:35:04
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com