Matrix dimensions must agree error when converting from jg2 to tiff

1 view (last 30 days)
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 Comments
Geoff Hayes
Geoff Hayes on 18 Mar 2019
Isaac - it may still be helpful to copy and paste the full error message.

Sign in to comment.

Accepted Answer

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

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!