Color Segmentation with Lab Space

6 vues (au cours des 30 derniers jours)
Zachary Mansley
Zachary Mansley le 30 Sep 2015
Commenté : Image Analyst le 30 Sep 2015
I am trying to segment images but am having trouble converting from RGB to Lab. What I am finding is that my program works for color images, but images that are predominantly black and white gives me errors. When I try:
he = imread('image.png');
lab_he = rgb2lab(he);
I get the error:
Error using images.color.ColorConverter/convert (line 218)
Mismatch between input size and the expected number of input color components.
Error in images.color.ColorConverter/evaluate (line 364)
out = convert(self, in);
Error in images.color.internal.Callable/subsref (line 15)
[varargout{1:nargout}] = self.evaluate(s(1).subs{:});
Error in rgb2lab (line 65)
lab = converter(rgb);
Error in Module1 (line 45)
lab_he = rgb2lab(he);
And when I try:
he = imread('image.png');
cform = makecform('srgb2lab');
lab_he = applycform(he,cform);
I get the error:
Error using applymattrc_fwd (line 18)
Incorrect number of columns in IN.
Error in applycform (line 88)
out = c.c_func(columndata, cdata{:});
Error in applycformsequence (line 11)
out = applycform(out, cforms{k});
Error in applycform (line 88)
out = c.c_func(columndata, cdata{:});
Error in applycformsequence (line 11)
out = applycform(out, cforms{k});
Error in applycform (line 88)
out = c.c_func(columndata, cdata{:});
Error in Module1 (line 44)
lab_he = applycform(he,cform);
The code works for a color picture of a red apple, but not for a black and white image of steel. Is there any way around this?

Réponses (1)

Image Analyst
Image Analyst le 30 Sep 2015
It's meant for color images. You're passing it a gray scale image. And there is no need to do anything in LAB color space with gray scale images. You should check and do the appropriate operations
[rows, columns, numberOfColorChannels] = size(he);
if numberOfColorChannels == 3
% It's color
lab = rgb2lab(he);
% Other stuff...
else
% It's probably gray scale.
% Do some gray scale processing.
end
  2 commentaires
Zachary Mansley
Zachary Mansley le 30 Sep 2015
Thanks! I am relatively new to image processing in Matlab and was using the k-means clustering code available on MathWorks. I'll now be looking into gray scale segmenting.
Image Analyst
Image Analyst le 30 Sep 2015
You can try graythresh() though I don't find that that works that great. You can try my interactive thresholding method: http://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image
Often for skewed histograms the triangle thresholding method works well. And a fixed threshold works great for situations where you can control your illumination.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by