How to load N images in 4 axes GUI Matlab

조회 수: 5 (최근 30일)
Lolipop
Lolipop 2014년 11월 20일
댓글: Lolipop 2014년 11월 21일
So my question is how am I going to load N images in 4 axes..I made push button and four axes so I can load one image and put it in first axes,so when I am loading second image I need to be uploaded in first axes and the image from the first axes to be moved to second axes. While loading third image,image from second axes need to be moved to third and first image to second axes and so on. Last image is always replaced by the penultimate.
I used this code but it works only for one image
[filename, foldername] = uigetfile({'*.*'}, 'Select file');
if filename ~= 0
FileName = fullfile(foldername, filename);
end
axes (handles.axes1);
F = imread (FileName);
imshow(F, 'Parent', handles.axes1);
s=F;
axes(handles.axes2);
imshow(s)
Please can anyone help me with this?

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 11월 20일
delila - I think that you can just switch/swap the data from each axes before you load the newest image into axes1. For example, suppose that in your GUI's OpeningFcn you default all of the axes data to a blank image like
defaultImg = uint8(zeros(400,400));
imshow(defaultImg,'Parent',handles.axes1);
imshow(defaultImg,'Parent',handles.axes2);
imshow(defaultImg,'Parent',handles.axes3);
imshow(defaultImg,'Parent',handles.axes4);
Now each of these axes has something that we can swap amongst each other. Now in your code that gets the next image, do something like
[filename, foldername] = uigetfile({'*.*'}, 'Select file');
if filename ~= 0
FileName = fullfile(foldername, filename);
img = imread(FileName);
% swap images
cdata = get(get(handles.axes3,'Children'),'CData');
set(get(handles.axes4,'Children'),'CData',cdata);
axis(handles.axes4,'tight');
cdata = get(get(handles.axes2,'Children'),'CData');
set(get(handles.axes3,'Children'),'CData',cdata);
axis(handles.axes3,'tight');
cdata = get(get(handles.axes1,'Children'),'CData');
set(get(handles.axes2,'Children'),'CData',cdata);
axis(handles.axes2,'tight');
% add the new image to axes1
set(get(handles.axes1,'Children'),'CData',img);
axis(handles.axes1,'tight');
end
In the above, we assume that each axes has exactly one child, and that that child corresponds to an image. We then take that image data (from the property CData) and copy it into the CData of the child graphics object in the subsequent axes (so that in 2 moves to 3, that in 3 moves to 4, etc.). We use the
axis(handles.axes4,'tight');
so that the our image fits into the axes (and so the latter doesn't try to re-adjust for images with different dimensions).
  댓글 수: 3
Geoff Hayes
Geoff Hayes 2014년 11월 21일
Delia - are you sure that you copied the code as above? See the attached demo which does the swapping of the images.
Lolipop
Lolipop 2014년 11월 21일
Thank you so much..it's working perfectly fine!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by