Allowing users to open up specific images during execution of code

조회 수: 1 (최근 30일)
Rachel Ball
Rachel Ball 2023년 11월 16일
답변: Image Analyst 2023년 11월 16일
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
DGM 2023년 11월 16일
편집: DGM 2023년 11월 16일
I never use it myself, but maybe imageDatastore() is a thing you could use.
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.
Robert
Robert 2023년 11월 16일
zrobić z tego strukturę dir

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

답변 (2개)

Walter Roberson
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")

Image Analyst
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.

카테고리

Help CenterFile Exchange에서 DICOM Format에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by