Estimate the color distribution by Guassian mixture model

457 views Asked by At

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.

1

There are 1 answers

2
drsealks On

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.