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

2 vues (au cours des 30 derniers jours)
-looking to dispaly multi (.mat) files as images
-save or crop the center then save the cropped images it
  7 commentaires
Mohamed Elbeialy
Mohamed Elbeialy le 24 Nov 2020
This is what I am looking to get help with
Image Analyst
Image Analyst le 24 Nov 2020
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.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 24 Nov 2020
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 commentaires
Image Analyst
Image Analyst le 25 Nov 2020
My images did not have a white frame. Are you sure you used imwrite() and not saveas(), print(), or exportgraphics()?

Connectez-vous pour commenter.

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by