Loading multiple DICOM images in App Designer and switching between them,

Hello,
I am creating an app using App Designer and I would like to be able to browse several DICOM images at the same time. I need the first one to show in the first place and then to be able to change to the next one by pressing a button.
Right now I have the code for browsing and showing only one DICOM file as it follows:
[fn, pn] = uigetfile({'*.dcm'},'select dicom file');
complete = strcat(pn,fn);
I = dicomread(complete);
imshow(I,[],'Parent',app.UIAxes);
I also have a button called "Next image", but I'm begginer and quite lost on how to achive what I need,

 Accepted Answer

I suggest that you use MultiSelect with uigetfile. Test the results to see if isnumeric(fn) and if so then the user cancel. Then fn=cellstr(fn); to make it easier to handle the case that the user selected exactly one file.
Now keep an app property which is the index of the current image. You could use a slider or a drop box to have the user select an image. In the callback, get the new value, make sure that it is in range, set the mentioned app property to the new index, and use the index to pull out the filename and display it.
Also please use fullfile() to build file names. uigetfile does not always put a directory separator at the end of the path it returns.

5 Comments

Thank you very much for your answer.
I have used MultiSelect as you suggested like this:
[fn, pn] = uigetfile({'*.dcm'},'select dicom file','MultiSelect','on');
Now it allows me to select multiple images as I wanted.
But I'm still having trouble with the app property and the callback for the button/slider/drop box. I don't know how to determine the index of my files if they have random names and I don`t really know how to set the property for it.
Could you please share with me an example of how it should look like?
You can set the Items property to the cell array of file names. The Value property would then be the file name.
Insted of a drop down menu I have tried to use a "Next" button with the following code:
idx = mod(app.currentidx + 1, length(app.Filelist));
if app.idx == 0
app.idx = 1;
end
app.load_image_at_index(idx);
I also have set Index as a property. But it doesn't work:
The first input argument must be a filename or DICOM info struct.
Error in dicomread (line 91)
[X, map, alpha, overlays] = newDicomread(msgname, frames, useVRHeuristic);
These errors only appear when selecting multiple images.
Is load_image_at_index a method of your class ?
You do not show how you are calling dicomread() after this revision
It has finally worked, thank you very much for your answer.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!