Effacer les filtres
Effacer les filtres

Matrix dimensions must agree error when converting from jg2 to tiff

2 vues (au cours des 30 derniers jours)
Isaac Lau
Isaac Lau le 18 Mar 2019
Commenté : Isaac Lau le 18 Mar 2019
I'm sort of confused... I'm trying to covert a folder of jp2's to tiffs and here's my code..... idk what's wrong with it and why matricies are even involved... Plz help!!!
% Specify the folder where the files live.
myFolder = '/Users/ironmanroxx/Desktop/VeggiesDownload/Extracted_Images';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jp2'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
[folder, baseFileNameYeet, extension] = fileparts(fullFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
img = imread(fullFileName);
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
imwrite(img, baseFileNameYeet + '.tiff');
end
  4 commentaires
Geoff Hayes
Geoff Hayes le 18 Mar 2019
Isaac - it may still be helpful to copy and paste the full error message.
Isaac Lau
Isaac Lau le 18 Mar 2019
Will do so in the future. Walter's answer helped!

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 18 Mar 2019
fileparts returns character vectors, not string objects. baseFileNameYeet is a character vector. You are trying to do arithmetic when you use + between two character vectors, and that will fail unless the two character vectors are the same length or one of the two character vectors is scalar.
If you have R2017a or later you could change the + '.tiff' to + ".tiff" . That would make use of string objects, for which + is defined as concatenation.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by