Matrix dimensions must agree error when converting from jg2 to tiff

2 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2019-3-18
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by