remove image from imageDatastore

조회 수: 11 (최근 30일)
Stefan Frenzel
Stefan Frenzel 2018년 4월 18일
댓글: Atsushi Ueno 2022년 3월 15일
I often encounter the need for excluding images from an imageDatastore object. One could remove the image from the corresponding file system directory and create the imageDatastore again, but that should not be the default way. How do I remove a single image once the imageDatastore has been defined?

답변 (1개)

karim botros
karim botros 2019년 3월 4일
I have been looking for the same issue, and i found an easy work around to remove specific images from the imagedatastore
where {1,1} is the index of the data you want to delete
data.Files = setdiff(data.Files,data.Files{1,1})
  댓글 수: 1
Atsushi Ueno
Atsushi Ueno 2022년 3월 15일
setdiff function removes only the relevant "Files" field and no other fields in this case.
The image data store object function that corresponds to the setdiff function is the subset function that has been introduced in R2019a.
You see "Files" and "Labels" field has been deleted as expected in the example below.
imds = imageDatastore(fullfile(matlabroot,"toolbox","matlab"),...
"IncludeSubfolders",true,"FileExtensions",".tif","LabelSource","foldernames")
imds =
ImageDatastore with properties: Files: { '/MATLAB/toolbox/matlab/demos/example.tif'; '/MATLAB/toolbox/matlab/imagesci/corn.tif' } Folders: { '/MATLAB/toolbox/matlab' } Labels: [demos; imagesci] AlternateFileSystemRoots: {} ReadSize: 1 SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage
delimg = matches(imds.Files, imds.Files{1,1});
subimds = subset(imds, ~delimg)
subimds =
ImageDatastore with properties: Files: { '/MATLAB/toolbox/matlab/imagesci/corn.tif' } Folders: { '/MATLAB/toolbox/matlab' } AlternateFileSystemRoots: {} ReadSize: 1 Labels: imagesci SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage

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

카테고리

Help CenterFile Exchange에서 Image Sequences and Batch Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by