How to batch process images from folder

10 visualizaciones (últimos 30 días)
Dimas Riansa
Dimas Riansa el 23 de Mayo de 2016
Comentada: Dimas Riansa el 24 de Mayo de 2016
Greetings, i have 100 signature images on a folder which would be preprocessed with this code
if true
I=imread('1.png');
%figure,imshow(I);
img=imresize(I,[256 ,256]);
%figure,imshow(img);
Im=rgb2gray(img);
Im=im2double(Im);
Im=im2bw(Im);
Im = bwmorph(~Im, 'thin',inf);
Im=~Im;
%figure,imshow(Im);
xstart=256;
xend=1;
ystart=256;
yend=1;
for y=1:256
for x=1:256
if((Im(y,x)==0)) %(y,x)
if (y<ystart)
ystart=y;
end
if((y>yend))
yend=y;
end
if (x<xstart)
xstart=x;
end
if (x>xend)
xend=x;
end
end
end
end
for i=ystart:yend
for j=xstart:xend
im((i-ystart+1),(j-xstart+1))=Im(i,j);
end
end
%figure,imshow(im);
end
what i wanted to ask is how do i batch call all those images and preprocess them, i've readed this question http://www.mathworks.com/matlabcentral/answers/7342-reading-multiple-images-in-a-folder-imread but it seems it can only be used if the name is the same eg.(image001,image002...) which is not the case with my images. they're all of the same file extension but have 10 different names eg(dimas1,fakedimas1...)
Thank you and sorry for the bad english

Respuesta aceptada

Image Analyst
Image Analyst el 23 de Mayo de 2016
See this nice framework that handles a lot of the stuff for you: http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component
Or if you want to do it yourself, not quite so fancy and nice, use the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
The code snippet you want is the second one.
  7 comentarios
Image Analyst
Image Analyst el 24 de Mayo de 2016
Yes of course you still need dir(). You got the error because you didn't follow the FAQ. You will get ALL files, even . and .. and folders, not just image files because you did not specify a file pattern. Either specify a file pattern like the FAQ showed you or you'll have to use isdir(fullFileName) to check whether or not the file is a folder instead of a file. Obviously using a file pattern is simplest.
Dimas Riansa
Dimas Riansa el 24 de Mayo de 2016
whoops was a bit confused first time since dir would only accept one input arguments once again thanks for pointing it out

Iniciar sesión para comentar.

Más respuestas (1)

Sean de Wolski
Sean de Wolski el 23 de Mayo de 2016
Editada: Sean de Wolski el 23 de Mayo de 2016
You could use the image batch processing app in recent releases. Either from the apps tab or:
>>imageBatchProcessor
  1 comentario
Dimas Riansa
Dimas Riansa el 24 de Mayo de 2016
Editada: Dimas Riansa el 24 de Mayo de 2016
it seems like mine R2014b doesn't have it

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by