필터 지우기
필터 지우기

How dispaly .mat as an image, then save it, then crop the saved image from the center ?

조회 수: 5 (최근 30일)
-looking to dispaly multi (.mat) files as images
-save or crop the center then save the cropped images it
  댓글 수: 7
Image Analyst
Image Analyst 2020년 11월 24일
If the help in my Answer below did not work for you, then attach one of the mat files with the paperclip icon and tell us what part of the center you want to save and what you'd like the output filename to be.

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

답변 (1개)

Image Analyst
Image Analyst 2020년 11월 24일
Use the FAQ to read in a sequence of lots of .mat files.
In the loop, get your image from the mat file then crop it. Here's a start.
% Specify the folder where the files live.
myFolder = pwd; % or wherever, like 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.mat'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
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()
s = load(fullFileName);
% See if this structure has a field called myImage or whatever it's called in your programs.
if isfield(s, 'myImage')
imageArray = imread(fullFileName);
imageArray = imageArray(row1:row2, col1:col2, :);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
fprintf('Displaying myImage from %s\n', baseFileName);
else
fprintf(' myImage not found in %s\n', baseFileName);
end
end
Of course you need to assign row1, row2, col1, and col2 according to how you'd like to do the cropping.
  댓글 수: 5
Image Analyst
Image Analyst 2020년 11월 25일
My images did not have a white frame. Are you sure you used imwrite() and not saveas(), print(), or exportgraphics()?

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

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by