-1

I want to read a training image set for SVM training. This is the code

  %Location of the image.
  Class1 = 'Training/11';
  % load the dataset
  dirList = dir(fullfile(Class1,'*.ppm'));
  %dirList
  files={dirList.name}';

The type of files that I got is of type cell. How I can access those images to perform something, like show it and do feature extraction??

When I tried to show it:

   figure, imshow(files)

I got this error

   Error using imageDisplayValidateParams
   Expected input number 1, I, to be one of these types:

   double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64,
   logical

   Instead its type was cell.

    Error in imageDisplayValidateParams (line 12)
    validateattributes(common_args.CData, {'numeric','logical'},...

    Error in imageDisplayParseInputs (line 79)
    common_args = imageDisplayValidateParams(common_args);

     Error in imshow (line 220)
     [common_args,specific_args] = ...

Do you know how to access and do some processing of these images in files?

MY FOLDER DIRECTORY!!

MY DIRECTORY

Inside my training Folder

rayryeng
  • 102,964
  • 22
  • 184
  • 193
user3175490
  • 51
  • 1
  • 1
  • 4

1 Answers1

2

First off, imshow requires an actual image as its input. You are specifying a cell array of strings. On top of that, you can only show one image at a time. Try accessing individual cell elements instead and using those to read in an image and display them on the screen.

im1 = imread(files{1}); % Read in first image
imshow(im1); % Show the first image
figure;
im2 = imread(files{2}); % Read in second image
imshow(im2); % Show the second image

If you want to display all of them, you could try using a combination of imshow and subplot.

Let's say you had 9 images, and wanted to organize them in a 3 x 3 grid. You could do something like:

figure;
for i = 1 : 9
    subplot(3, 3, i);
    im = imread(files{i});
    imshow(im);
end

Now for performing feature extraction, my suggestion is that you take a look at the Computer Vision toolbox that is accompanied with MATLAB. There is a whole suite of tools that performs feature extraction for you. Things like MSER, SURF, HOG and methods to match keypoints between pairs of images.

Check this link out: http://www.mathworks.com/products/computer-vision/code-examples.html

rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • I got this error --> Error using imread (line 350) File "01153_00000.ppm" does not exist. – user3175490 Apr 06 '14 at 09:42
  • That's because the image does not exist in your working directory. At the top of MATLAB, change the working directory to be where the images are located. If you want to avoid changing the working directory, then use absolute paths. **FWIW:** MATLAB error messages are very insightful. Suggest you read the messages very carefully before posting. – rayryeng Apr 06 '14 at 09:51
  • Heyy,, please have a look at image I just uploaded.. There u can see that I have 2 folder (training and testing) and in training folder I have another folders that consist of different classes. How should I change the directory? To be automatically read all the images of diffrent claseesc (folders) – user3175490 Apr 06 '14 at 09:55
  • You can invoke command prompt / terminal commands directly in MATLAB. Do `cd/training` to go into the `training` folder before running your code, then do `cd..` `cd/testing` for the testing folder. However, if you want to grab every single file from a directory and recursively its subdirectories, check this SO post: http://stackoverflow.com/questions/2652630/how-to-get-all-files-under-a-specific-directory-in-matlab. **NB:** Have a look and search on SO for questions related to what you're going to ask before posting. Minimizes clutter. – rayryeng Apr 06 '14 at 10:00
  • Heyy,, sorry to disturb u againn,, but i already used this command dirData = dir(D:\COBA);,, but still get an error.. Do u know what dir value is supposed to be? – user3175490 Apr 06 '14 at 10:22
  • Hayyy, can u lease help me.. I set my directory name but I still get error --> Error: Unexpected MATLAB operator...Please – user3175490 Apr 06 '14 at 10:48
  • Enclose the directory in single quotes. **FYI:** This will be the last time I help you. Suggest you look at MATLAB help or search the SO forums for answers. The questions you ask can easily be found in MATLAB help or on SO. – rayryeng Apr 06 '14 at 15:53