how to show one by one jpg images using slider from the folder
Show older comments
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)
Image Analyst
on 10 Sep 2013
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
Muhammad
on 11 Sep 2013
Image Analyst
on 11 Sep 2013
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
Muhammad
on 11 Sep 2013
Image Analyst
on 11 Sep 2013
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!
Muhammad
on 12 Sep 2013
Image Analyst
on 12 Sep 2013
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);
Muhammad
on 12 Sep 2013
Image Analyst
on 12 Sep 2013
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;
Muhammad
on 12 Sep 2013
Categories
Find more on Scripts in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!