Loading images in a variable..
34 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Junaid
le 30 Avr 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 commentaires
ayushi
le 21 Juil 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
le 21 Juil 2016
if strcmp(VariableWithSelectedImageName, 'image1')
imshow(image2);
elseif strcmp(VariableWithSelectedImagename, 'image2')
imshow(image4);
end
Plus de réponses (9)
Junaid
le 30 Avr 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
le 30 Avr 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 commentaires
Junaid
le 1 Mai 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 commentaires
Junaid
le 1 Mai 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 commentaires
Alex
le 30 Avr 2012
1 commentaire
Image Analyst
le 1 Mai 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
le 1 Mai 2012
3 commentaires
Image Analyst
le 1 Mai 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
le 14 Avr 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 commentaire
Walter Roberson
le 14 Avr 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);
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!