how to show one by one jpg images using slider from the folder

Dear all
Hope you are keeping Good and enjoying well. i have 55 jpg images i displayed them on Axes but all the images frequently passes in front of me. i want to show images one by one using by clicking on slider. how i use slider in this code please? i need to work on every image. any help is appriciated in advance.
Isa
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
myFolder = 'C:\Users\khanm\Desktop\image files';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.jpg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end

Answers (1)

Here is some code from a listbox click callback. You can do similar just put it in your scrollbar callback:
% Get image name
Selected = get(handles.lstImageList, 'value');
% If more than one is selected, bail out.
if length(Selected) > 1
% Change mouse pointer (cursor) to an arrow.
set(gcf,'Pointer','arrow')
drawnow; % Cursor won't change right away unless you do this.
return;
end
% If only one is selected, display it.
% Get list of ALL the filenames in the listbox.
ListOfImageNames = get(handles.lstImageList, 'string');
% Get the one name they selected.
baseImageFileName = strcat(cell2mat(ListOfImageNames(Selected)));
fullImageFileName = [handles.ImageFolder '/' baseImageFileName]; % Prepend folder.
imshow(fullImageFileName);
My image names were stored in a listbox. If yours aren't then just do whatever you need to do to get the image. For example if the slider value is 13, just get image #13 from your cell array of filenames.

10 Comments

thank you for your earlier response. dear image analyst actually i am new and dont know much about MATLAB GUI but keeping to understand. i have all images in a folder. how will i call slider to to show those images on axis one by one. i click on the slider arrow then will find new image and do on work on that but at this time as i can see all images like a forwarded movie playing in the axis with the code i sent. please look at that and guide me. thanks.
That's not even a good method so I don't want to tell you how to do it. You'd have a much more user friendly UI if you had a listbox with images that the user can click on, like MAGIC does it: http://www.mathworks.com/matlabcentral/fileexchange/24224
But i am unable to watch the file. i downloaded the submission but how can i use such a huge file Sir?
If you want, just place a listbox on your form and copy the insides of the MAGIC listbox callback function to yours. You can do it - you're a smart guy!
Dear i used the listbox by using mathsworks answer and reached at this point. Now, i really your need. Now, i can get any fig from list box to display on axes. this is done by using the below code.
Code For opening function
if
function VOLUME_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.cdir = pwd;
set(handles.listbox1,'enable','off');
guidata(hObject, handles);
Code For listbox1 function if true
function listbox1_Callback(hObject, eventdata, handles)
handles.output = hObject;
index = get(handles.listbox1,'value');
imshow(handles.I{index});
guidata(hObject, handles);
end
Code For opening folder function
if true
handles.output = hObject;
fn = uigetdir(handles.cdir,'Select directory');
if fn ~= 0
handles.cdir = fn;
img = dir(fullfile(handles.cdir,'*.jpg'));
for x = 1 : length(img)
handles.I{x} = imread(fullfile(handles.cdir,img(x).name));
end
if length(img) ~= 0, set(handles.listbox1,'enable','on');
else, set(handles.listbox1,'enable','off');
end
set(handles.edit1,'string',handles.cdir);
set(handles.listbox1,'string',{img.name});
end
guidata(hObject, handles);
end
Now, i want to zoom some part by using some Zoompushbutton and then contour some region using imfreehand and then i have i want all the coordinates of the region in in a excel sheet. excel sheet will appear using pushExcel button. waiting for your kind reply.
i am also sending you my code which i write for a image but i need to apply this as a told you on the above code. (this code hopefully will tell you what i want to do on a image)
if true
I = imread('cat.jpg');
imshow(I);
% image;
zoom on; % use mouse button to zoom in or out
% Press Enter to get out of the zoom mode.
% CurrentCharacter contains the most recent key which was pressed after opening
% the figure, wait for the most recent key to become the return/enter key
waitfor(gcf,'CurrentCharacter',13)
zoom reset
zoom off
% imfreehand
% the figure, wait for the most recent key to become the return/enter key
h=imfreehand(gca,'closed',0);
pos = getPosition(h);
sz = size(I);
maskedImage = poly2mask(pos(:,1), pos(:,2), sz(1), sz(2));
imshow(maskedImage)
[Y, X] = find(maskedImage ~= 0);
end
dear Sir i reached at this point and now i need your help please. Help is appreciated in advance.
  • * i programmed a pushbutton which do zoom the code is given below.,
  • * i have another pushbutton which is contour and contour the some part of image by imfreehand and then make mask and calculate the all coodinates in that region.
i need another pushbutton (creat excel file) that will show those contoures results on excel sheet.
Zoom button
if true
zoom on; % use mouse button to zoom in or out waitfor(gcf,'CurrentCharacter',13) zoom reset zoom off set(handles.listbox1,'string',{img.name}); endContour Button
if true
function Contourpushbutton_Callback(hObject, eventdata, handles)
% imfreehand
% the figure, wait for the most recent key to become the return/enter key
h=imfreehand(gca,'closed',0);
pos = getPosition(h);
end
if true
h=imfreehand(gca,'closed',0);
pos = getPosition(h);
sz = size(handles.listbox1);
maskedImage = poly2mask(pos(:,1), pos(:,2), sz(1), sz(2));
imshow(maskedImage)
[rows, columns] = find(maskedImage ~= 0);
data=[rows,columns]; end
You have to give it a zoom value - like from a scrollbar - you can't just set it on or off. I'm not going to have much time to put into your project today. I don't see much use for getting "data" in the last chunk of code. Why get the row numbers and column numbers of where the mask is? Of what use is that? Also, in poly2mask you need to provide the vertices and the number of rows and columns in the image, not the size of the handle, which is a scalar ID number to a graphical element (the listbox).
yourImageArray = imread(fullFileNameString);
[rows, columns, numberOfColorChannels] = size(yourImageArray);
actually i want to calculate the volume inside the region i made with imfreehand. so i do like above. form above i can calculate all (rows columns) or (Y X) coordinates then i will multiply these with the tickness of the image to get the volume inside the region. am i right dear? i am a new in MATLAB so, if possible then suggest me some literacture to rea and understand. isa
That's the right concept but the wrong execution. Do it like this, for one slice image:
% Turn the hand drawn coordinates into a logical mask.
mask = poly2mask(pos(:,1), pos(:,2), rows, columns);
% Sum up all the pixels inside the mask to get the area of this slice.
thisSlicesArea = sum(mask(:));
% Now multiply by the separation between slices to get the volume.
thisSlicesVolume = thisSlicesArea * yourSliceSeparation;
No, i dont want the area. i want coordinate of every pixel on a excel sheet so that i will calculate the Volume of every pixel and then i have a excel sheet which contains X, Y, Z, Volume (XxYxZ). these are all in seprate seprate columns.

Sign in to comment.

Categories

Find more on Scripts in Help Center and File Exchange

Tags

Asked:

on 10 Sep 2013

Community Treasure Hunt

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

Start Hunting!