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.

 Réponse acceptée

Image Analyst
Image Analyst le 11 Oct 2021

0 votes

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

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by