Convert multiple images in a single .mat file into jpg images
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Shourya
el 28 de En. de 2022
Comentada: Shourya
el 8 de Feb. de 2022
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.
0 comentarios
Respuesta aceptada
Image Analyst
el 28 de En. de 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 comentarios
Image Analyst
el 1 de Feb. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!