Converting 6 Pic into Matlab data
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, i wanna ask about how do you change 6 image into matlab data
i have 6 images of surfaces that i want to convert, which is these
That 6 images i want to change into
So i try to clicked "generate matlab code" and matlab automaticly generate these code
As u can see there's an error "Unrecognized function or variable 'File''
Can anyone help me with this?? thanks
1 commentaire
Rik
le 2 Juin 2023
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
Réponse acceptée
Walter Roberson
le 4 Mar 2023
jpeg files do not contain variables.
jpeg files contain 2d arrays of uint8 (occasionally, but rarer than February 29th's) or 3d arrays of uint8 (nearly all of the time.)
Sometimes there is accessible header information such as the shutter speed.
jpeg files never contain logical data.
jpeg files contain double precision data only in the headers.
jpeg files never contain color maps or alpha data.
The only time a jpeg could contain a 65536 x 3 array would be if it were a grayscale image with 65536 rows and 3 columns.
You can never use load() to read jpeg files.
Your code is completely unsuited for reading image files.
5 commentaires
Walter Roberson
le 4 Mar 2023
You did not assign a value to a variable named 'File'. You happen to have a folder named 'File' Having a folder with a particular name is not at all the same as assigning a variable with the name.
If you were to assign
File = 'File';
then you would be passing a folder name to the code. However the code does not expect to be passed the name of a folder: it expects to be passed the name of a .mat file.
Is it possible make the images into mat files? Possibly.
- what do you want the mat files to be named?
- what variable names do you want in the mat files?
- what information do you want to retrieve from the image files to store into the mat files?
- what is the reason for storing the information in mat files instead of just reading the image files when you need them?
- do you want one overall mat file, or do you want one mat file per image?
Walter Roberson
le 4 Mar 2023
The following function accepts a character vector or string scalar that is the name of a folder .
It returns a cell array of the contents of the images in the folder, and a cell array of the image file names that were successfully read.
Any images that are detected as being pseudocolor are converted by RGB.
grayscale images are not converted to RGB automatically.
Example of use:
[img_cell, filenames] = import_image_folder("File");
You can then take the contents of the cell and the filenames and convert them into whatever form of .mat file (or files) that suit your needs.
function [image_cell, filenames] = import_image_folder(foldername)
if nargin < 1
error('must provide folder name as char as string scalar');
end
foldername = convertStringsToChars(foldername);
if ~ischar(foldername)
error('must provide folder name as char as string scalar');
end
if ~isfolder(foldername)
error('folder "%s" does not exist', foldername);
end
dinfo = dir(foldername);
image_cell = {};
filenames = {};
for K = 1 : length(dinfo)
if dinfo(K).isdir; continue; end
filename = fullfile(dinfo(K).folder, dinfo(K).name);
try
[img, cmap] = imread(filename);
if ~isempty(cmap); img = ind2rgb(img, cmap); end
image_cell{end+1} = img;
filenames{end+1} = filename;
catch ME
fprintf(2, '%s is not an recognizable image\n', dinfo(K).name);
end
end
end
Plus de réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!