Azzera filtri
Azzera filtri

Convert multiple images in a single .mat file into jpg images

3 visualizzazioni (ultimi 30 giorni)
There is a .mat file that contains images and I don't have much information about it. I'd like to convert each of these images stored in the single .mat file to jpg and view them. I would also like to know why these images are stored in a single .mat file as opposed to multiple .mat files. Please help.

Risposta accettata

Image Analyst
Image Analyst il 28 Gen 2022
Who knows why they chose a single one instead of multiple files. Anyway, to get the images out, assuming they are called iamge1, image2, etc.
s = load(fullFileName)
imwrite('image1.png', s.image1); % Don't use jpg or you'll have compression artifacts.
imwrite('image2.png', s.image2); % Don't use jpg or you'll have compression artifacts.
imwrite('image3.png', s.image3); % Don't use jpg or you'll have compression artifacts.
  7 Commenti
Image Analyst
Image Analyst il 1 Feb 2022
You have to figure out how many patches (images) are across that, and then divide the image up into parts
numImages = 8; % Or whatever it is.
s = load('file_one.mat')
output_array = s.output_array;
[rows, columns, numberOfColorChannels] = size(output_array);
if numberOfColorChannels == 3
output_array = rgb2gray(output_array);
end
% Extract and display them all in separate subplots.
columnsPerPatch = floor(columns / numImages)
plotRows = ceil(sqrt(numImages));
k = 1;
for col = 1 : columnsPerPatch : columns
thisImage = output_array(:, col : col + columnsPerPatch - 1);
subplot(plotRows, plotRows, k);
imshow(thisImage, []);
k = k + 1;
end

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by