Borrar filtros
Borrar filtros

Matrix dimensions must agree error when converting from jg2 to tiff

2 visualizaciones (últimos 30 días)
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 comentarios
Geoff Hayes
Geoff Hayes el 18 de Mzo. de 2019
Isaac - it may still be helpful to copy and paste the full error message.
Isaac Lau
Isaac Lau el 18 de Mzo. de 2019
Will do so in the future. Walter's answer helped!

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Mzo. de 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.

Más respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by