0

I have an Image and i want to estimate the color distribution of the input image by a Gaussian Mixture Model, how i can do it with Matlab?

myImage = imread('Jellyfish.jpg');

gmdistribution.fit(X,k) is not work for me, because X must be a 2D Matrix and myImage is 3D Matrix, i get this error when use gmdistribution.fit(myImage,10): X must be a numeric 2-D matrix.

when i use gmdistribution.fit(myImage(:,:,1),10) for Red color of Image i get this error:

Error using var (line 59)
First argument must be single or double.

Error in gmdistribution.fit (line 133)
varX = var(X);

and when i use : gmdistribution.fit(single(myImage(:,:,1)),10) i give this error:

Error using gmcluster (line 180)
Ill-conditioned covariance created at iteration 2.

Error in gmdistribution.fit (line 174)
    [S,NlogL,optimInfo] =...

i want to use this for an Image Segmentation using Gaussian Mixture Models. if you have any idea, help me.

AliSh
  • 10,085
  • 5
  • 44
  • 76

1 Answers1

0

Just call it like this

gmdistribution.fit(single(myImage(:,:,1)),10)

The point is that by default RGB image is loaded as array of integer elements. You're said that this function cannot accept integer elements - it need single of double(floating point data types). You can do this by explicit type conversion.

drsealks
  • 2,282
  • 1
  • 17
  • 34
  • i get this error : Error using gmcluster (line 180) Ill-conditioned covariance created at iteration 2. – AliSh Nov 28 '14 at 15:28
  • Well, that, I suppose, problem of your data. A matrix is ill-conditioned if the condition number is too large (and singular if it is infinite). You can read more about conditional number here http://en.wikipedia.org/wiki/Condition_number – drsealks Nov 28 '14 at 15:32