rinku
rinku

Reputation: 415

Convert PNG images to pixel gray-level values feature vectors

I am a newbie in MATLAB and I have a set of bmp images which I need to convert into pixel gray-level values as feature vectors of image. Can anyone suggest me the way how I can do that? I need to use these pixel gray-level values as features and then perform operations like PCA/LDA. I tried imread() but it returns me a matrix.. I feel feature vector will be just one row vector.

Regards,

Upvotes: 1

Views: 2529

Answers (1)

John Colby
John Colby

Reputation: 22588

imread() is the correct way to do it. Then just convert from a matrix into a vector. For example:

>> X = randi(255, 10)

X =

   208    41   168   181   112    71   192   215    90    20
   231   248    10     9    98   174    66    65   212    14
    33   245   217    71   196   168   130   208   150   136
   233   124   239    12   203    42   179    63   141   199
   162   205   174    25    48    31   228   237   234   239
    25    37   194   210   125   128   245    90    73    34
    72   108   190   178   114   245   140    51   194   146
   140   234   101    81   165    87    36    65   193   120
   245   203   168   243   181   150    39   158    98     4
   247   245    44     9   193    58    66   121   145    86

>> X(:)

ans =

   208
   231
    33
   233
   162
    25
    72
   140
   245
   247
...

Then you can just stack your different observations together with [] and do PCA.

Upvotes: 1

Related Questions