フィルターのクリア

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

5 ビュー (過去 30 日間)
Mohamed Elbeialy
Mohamed Elbeialy 2020 年 11 月 23 日
コメント済み: Mohamed Elbeialy 2020 年 11 月 25 日
-looking to dispaly multi (.mat) files as images
-save or crop the center then save the cropped images it
  7 件のコメント
Mohamed Elbeialy
Mohamed Elbeialy 2020 年 11 月 24 日
This is what I am looking to get help with
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()?
Mohamed Elbeialy
Mohamed Elbeialy 2020 年 11 月 25 日
Got it. Thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by