Clear Filters
Clear Filters

How read multiple image to Matlab memory

3 views (last 30 days)
I would like to aks You how can I read a multiple image to Matlab ? I have n foto in Folder on my laptop and I need to put all of them into Matlab memory and then I need to convert image to binary image and after that I need convert all my image to double precision. I try make it with for loop but I have no idea how should to do. All od this steps are needed because I would like to make a Neural Network to Recognize a Road Sing. Now I have something like that:
% B=imread('A6E.png'); %Image 1
% B=im2bw(B);
% B=double(B);
%
% C=imread('A6D.png'); %Image 2
% C=im2bw(C);
% C=double(C);
True is, in this way I need all day to put all of my patterns. Someone give me some advice ?
Thank You.
  2 Comments
Stephen23
Stephen23 on 31 May 2018
Pawel Osadnik's "Answer" moved here:
function results = myvarfcn(var)
image = imread(var);
imBW = im2bw(image);
imDouble = double(imBW);
reimage = reshape(imDouble,40000,1);
results.image = image;
results.imBW = imBW;
results.imDouble = imDouble;
results.reimage = reimage;
end
I have something like this and it is working, but... Answer is 1-by-1 structure with all (4) results. Ok, but how can I upload (all at once) files into this function ? And after that I need one big structure or many structure with results from my files.
For my NN need one Matrix with all patterns.
Thank.

Sign in to comment.

Accepted Answer

Florian Morsch
Florian Morsch on 30 May 2018
You could use the the Image Batch Processor if you have it at hand: https://de.mathworks.com/help/images/batch-processing-using-the-image-batch-processor-app.html
Here you can load all images from a file and do something with them ( Your function would look something like this:
function results = myimfcn(im)
%Image Processing Function
%
% IM - Input image.
% RESULTS - A scalar structure with the processing results.
%
%--------------------------------------------------------------------------
% Auto-generated by imageBatchProcessor App.
%
% When used by the App, this function will be called for every input image
% file automatically. IM contains the input image as a matrix. RESULTS is a
% scalar structure containing the results of this processing function.
%
%--------------------------------------------------------------------------
% Replace the sample below with your code----------------------------------
imBW = im2bw(im);
imDouble = double(imBW);
results.imBW = imBW;
results.imDouble = imDouble;
%--------------------------------------------------------------------------
The batch processor app loads all images you tell it, uses the function you insert on the images and then you can save the results as you please.
  5 Comments
Stephen23
Stephen23 on 31 May 2018
@Pawel Osadnik: Your function definition is part of the problem:
function results = myimfcn(im)
im = imread('K9.png');
The input im (whatever it might be) is completely ignored because you totally redefine im on the first line of code. If you actually want to use the input values (e.g. when calling then function in a loop, which is the solution to your question), then redefining im inside the function does not help you.
Pawel Osadnik
Pawel Osadnik on 31 May 2018
Edited: Pawel Osadnik on 31 May 2018
I now about it, my mistake. I change this for code: And use Image Batch Processor App.
function results = myimfcn(im) %Image Processing Function % % IM - Input image. % RESULTS - A scalar structure with the processing results. %
%-------------------------------------------------------------------------- % Auto-generated by imageBatchProcessor App. % % When used by the App, this function will be called for every input image % file automatically. IM contains the input image as a matrix. RESULTS is a % scalar structure containing the results of this processing function. % %-------------------------------------------------------------------------- % Replace the sample below with your code----------------------------------
imBW = im2bw(im);
imDouble = double(imBW);
imReshape = reshape(imDouble,40000,1);
results.imBW = imBW;
results.imDouble = imDouble;
results.imReshape = imReshape;
And now I have my files in matlab but as Struct. And this problem because NN need matrix. My one cell in struct is a 40000x1 and this I need to have in my Workspace.
imReshape
____________
40000x1 double % This I need to have in Workspace as a single Matrix
40000x1 double
40000x1 double
40000x1 double
etc
Any idea how to "convert" struct to matrix ?

Sign in to comment.

More Answers (1)

Pawel Osadnik
Pawel Osadnik on 31 May 2018
I make it. Thank for Your help.

Community Treasure Hunt

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

Start Hunting!