reading specific png files

5 views (last 30 days)
dipon roy
dipon roy on 11 Oct 2021
Answered: Image Analyst on 11 Oct 2021
In a folder I have a PNGFiles subfolder and several jpeg and overlay files. I want to read the png files with the same name as the .OVERLAY.
Can anyone help?Thanks.

Accepted Answer

Image Analyst
Image Analyst on 11 Oct 2021
Untested code:
filePattern = fullfile(pwd, '**\*.png'); % Wildcard recurses into subfolders
fileList = dir(filePattern);
for k = 1 : numel(fileList)
% Build the full filename of the PNG file in the PNG folder.
pngFullFileName = fullfile(fileList(k).folder, fileList(k).name);
% Get the base filename of the PNG file, without the extension.
[folder, baseFileNameNoExt, ext] = fileparts(pngFullFileName);
% Get the overlay file for this image in the current folder (one level up)
ovlFullFileName = fullfile(pwd, [baseFileNameNoExt, '.overlay'])
% If it doesn't exist, skip this file.
if ~isfile(ovlFullFileName)
warningMessage = sprintf('Warning: Overlay file does not exist:\n%s', ovlFullFileName);
uiwait(warndlg(warningMessage));
contiue;
end
overlayImage = imread(ovlFullFileName);
% Do something with the PNG file and the overlay file.
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!