Allowing users to open up specific images during execution of code
2 次查看(过去 30 天)
显示 更早的评论
I am coding a project to allow sets images to be segmented, I want the user to be able to import a folder that contains the images, similar in style to the import data function in matlab located in the home tab. I then want to make a dir structure out of this, however I know how to do this.
3 个评论
DGM
2023-11-16
编辑:DGM
2023-11-16
Generally, blindly trying to read any random images that might be in a directory can become problematic if you're unable to predict what sorts of images might be present. Size, class, color type, channel count, framecount, orientation could vary. I'm assuming your cases will be fairly predictable and consistent, but it's good to be cautious.
That said, if you hope someone else will give you a "read any images in this directory" code, you'll probably want to narrow down the specific sorts of images you hope to support/exclude.
Consider the answers here:
My own answer there emphasizes input flexibility, but it depends on a FEX library, and is not compatible with an incremental workflow (i.e. operating on one file at a time). Either way, mimread() is ~280 lines of code. That's an example of the volume of code needed to handle a fairly broad set of assumed input cases.
回答(2 个)
Walter Roberson
2023-11-16
imagedir = uigetdir('Select an image directory');
if ~ischar(imagedir); return; end %user cancelled
known_extensions = [imformats().ext];
dinfo = dir(imagedir);
dinfo([dinfo.isdir]) = [];
[~, ~, fileext] = fileparts({dinfo.name});
dinfo = dinfo(ismember(lower(filext), lower(known_extensions)));
Now dinfo is a dir struct that has had all folders removed from it, and has been pruned down to only have files whos name ends with one of the image file formats known to imread() on your system. Different operating systems support different image file formats, so the list might not include everything that the user thinks are image files.
The files in dinfo will very likely not contain any dicom files. It is not uncommon for people to think of DICOM files as being "image" files. If you need to support DICOM files, then you cannot do any filtering of the files in the directory by file extension, since DICOM images do not have a standard file extension (".dcm" is common, but not a "standard")
0 个评论
Image Analyst
2023-11-16
See the FAQ for code samples.
Modify the inside of the loop to call some function, that you write like "AnalyzeSingleImage", that will analyze each image one at a time. In this way you can analyze a whole folder of images. Adapt the code as needed.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!