Loading images in a variable..
37 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alex
el 30 de Abr. de 2012
Comentada: Walter Roberson
el 14 de Abr. de 2019
HEllo, we are working on DIP based signature verification project. We are having problem in loading images in a variable & how to access every image using that variable. Any help would be appreciated.
Regards Alex
0 comentarios
Respuesta aceptada
Junaid
el 30 de Abr. de 2012
let say your Directory where you image is
myDir = 'images/';
and extension of all images are jpg
ext_img = '*.jpg';
now load images in a;
a = dir([myDir fileExtension]);
nfile = max(size(a)) ; % number of image files
now loop to read the images
for i=1:nfile
my_img(i).img = imread([myDir a(i).name]);
end
Now my_img contains all the images in given directory.
2 comentarios
ayushi
el 21 de Jul. de 2016
@ junaid if there is a image selected from a location and we want to check whether the image is image 1, and if the image is 1mage1 then imshow(image2) else if image is 1mage2 then open image 4
Walter Roberson
el 21 de Jul. de 2016
if strcmp(VariableWithSelectedImageName, 'image1')
imshow(image2);
elseif strcmp(VariableWithSelectedImagename, 'image2')
imshow(image4);
end
Más respuestas (9)
Junaid
el 30 de Abr. de 2012
to load image in a variable.
a = imread('myimage.jpg');
and you can check ...
imshow(a);
and you can do any operation on a. a contains single image. If you are storing 2-D image (gray scale image) then you can add multiple images on different channel.
For example. I have two 2-D images, a and b.
then c which contains both images.
c (:,:,1) = a;
c (:,:,2) = b;
Make sure a, and b both have same size (dimensions). This is as simple as you can. But there are many other ways like
And if you want to store the array of images. then following code can be usefull.
array(1).img = a;
array(2).img = b;
and so on.
Image Analyst
el 30 de Abr. de 2012
See the FAQ for a variety of ways to load a sequence of files: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
0 comentarios
Junaid
el 1 de Mayo de 2012
There are number of methods to compare two images. Most famous are Histogram based comparison, Entropy based comparison-- these methods captures the global properties of image.
Or now a days local features based comparison is used like SIFT based, SURF based etc.
%%
and if you want to compare two images from variables and you have difficulties to do any process then following example will subtract one image from the second (if both images have same resolution, dimensions).
C = my_img(1).img - my_img(2).img;
now c stores the an other image which is obtained by subtracting the image 1 and image 2.
0 comentarios
Junaid
el 1 de Mayo de 2012
you share what is your error and also post that in error as new Question.
In given code.
([*.jpg']);
should be this
(['*.jpg']);
and it should be written like this.
a = 'C:\Desktop\sai\*.jpg';
There should not be any semicolon.
0 comentarios
Alex
el 30 de Abr. de 2012
1 comentario
Image Analyst
el 1 de Mayo de 2012
Use fullfile() and maybe dir instead of whatever mess it is that you have there. Didn't I already refer you to the USC bibliography on signature comparison yesterday?
Alex
el 1 de Mayo de 2012
3 comentarios
Image Analyst
el 1 de Mayo de 2012
Your first code prints out the names of m-files to the command window, while the second code prints out names of JPG files. Why did you choose these limits and do you know that you have that many files. That is not a very robust way. You should do something like
for k = 1 : length(av_files) or for k = 1 : length(imagelist). Other than that I don't see anything off the top of my head why either would not work, unless you just don't have 35 jpg images in the folder, or 15 m-files in the folder. Do you have a specific error? Do the names get printed out to the command window?
Zeeshan Salam
el 14 de Abr. de 2019
can anyone tell me how to store image in I variable that run in that function? i cant run this code due to not load of image in I varibale?
function J = amedfilt2_calc(I) %#eml
% 2-D Adaptive Median Filter
% This filter ignores edge effects and boundary conditions, as such, the
% output is a cropped version of the original image, where the amount
% cropped is equal to the maximum window size vertically and horizontally.
% Define smax as a constant
smax = 9;
% Initialize Output Image (J)
J = I;
% Calculate valid region limits for filter
[nrows ncols] = size(I);
ll = ceil(smax/2);
ul = floor(smax/2);
% Loop over the entire image ignoring edge effects
for rows = ll:nrows-ul
for cols = ll:ncols-ul
window_ind = -ul:ul;
region = I(rows+window_ind,cols+window_ind);
centerpixel = region(ll,ll);
for s = 3:2:smax
% We can collapse the ROI calculations into a single function
[rmin,rmax,rmed] = roi_stats(region,smax,s);
% adapt region size
if rmed > rmin && rmed < rmax
if centerpixel <= rmin || centerpixel >= rmax
J(rows,cols) = rmed;
end
% stop adapting
break;
end
end
end
end
1 comentario
Walter Roberson
el 14 de Abr. de 2019
That code assumes that the input array is 2D -- a grayscale image.
If you are using imread() to read a .jpg file, then it is quite unlikely that it is a grayscale image, even if it looks gray. The original JPEG specification did not permit grayscale images, and although it was added afterwards, most software did not bother implementing it. JPEG images that look gray are almost always stored as RGB images.
The general procedure would be something like,
filename = 'SomethingAppropriate.png'; %use appropriate name and extension
img = imread(filename);
if size(img,3) > 1
img = rgb2gray(img);
end
J = medfilt2_calc(img);
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!