Azzera filtri
Azzera filtri

Matrix dimensions must agree error when converting from jg2 to tiff

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Geoff Hayes
Geoff Hayes il 18 Mar 2019
Isaac - it may still be helpful to copy and paste the full error message.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 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.

Più risposte (0)

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by