The problem with the above approach is that it doesn't really skip the null files, since I still need to define what 'data' is.
Remove empty image file in a ImageDatastore
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a folder containing images, some of which are empty JPEG (Zero byte). How can I create a ImageDatastore and skip the null files?
I have tried using ReadFcn to create a custom read function, see below:
function data=readImages(filename)
try % Fetch dimensions of a JPEG, error returned if it is null
dim = infinfo(filename);
data = imread(filename);
catch error
disp('Null data detected') % Problem: need to define data value for this statement
end
end
댓글 수: 2
Drishan Poovaya
2021년 8월 10일
I understand you want to avoid including any empty jpg files. For reference purposes, could you please attach one of these empty jpg files? It would be helpful to come up with a solution
답변 (1개)
Jayanti
2025년 5월 14일
Hi,
To ensure only valid images are used, you can first scan the image folder and filter out any files that are 0 bytes. And while creating the “ImageDatastore” only include those verified files. This way you will only have good images in your datastore.
Hope this will be helpful!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!