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

조회 수: 6 (최근 30일)
Shourya
Shourya 2022년 1월 28일
댓글: Shourya 2022년 2월 8일
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.

채택된 답변

Image Analyst
Image Analyst 2022년 1월 28일
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
Image Analyst
Image Analyst 2022년 2월 1일
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
Shourya
Shourya 2022년 2월 8일
Thank you for your response. It worked!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by