Clear Filters
Clear Filters

Help in understanding Color-Based Segmentation Using the L*a*b* Color Space Example

6 views (last 30 days)
Hi I am working on the picture I have attached below. I want to extract the boxes out of the picture by using Color Segmentation, for that I am following the example
But I have problem in understanding following things.
  1. what are " regioncoordinates"
  2. What happens in the step 17. lab_fabric = RGB2Lab(fabric);
  3. My picture doesn't have pure red,green and blue components, How can I modify this example for my boxes.

Answers (1)

DGM
DGM on 5 May 2023
Edited: DGM on 5 May 2023
The line:
load regioncoordinates;
loads the file regioncoordinates.mat. This file contains a variable called region_coordinates, which is a 5x2x6 array of coordinates in image space, defining the vertices of six polygons. These coordinates are used with polygonal selection tools (e.g. roipoly()) to create masks for sampling certain image regions.
These coordinates could be interactively generated any number of ways, using ROI tools like drawpolygon(), impoly(), or basic tools like getpts() or ginput(). If using drawpolygon() or impoly(), there's no need to use roipoly(), as you could generate the masks directly from the ROI object instead.
In any case, the goal is merely to obtain addressing information to select an image region. Any method which creates a logical mask or provides any other means of addressing a particular set of pixels would suffice.
% load the image
fabric = imread('fabric.png');
imshow(fabric); hold on
title('Fabric')
% load a variable called region_coordinates
% this is a 5x2x6 array (columns are [x y])
% each page is a vertex list describing a polygon in image coordinates
load regioncoordinates;
% idk why there's a redundant vertex in every polygon
% but it could be deleted without changing anything
region_coordinates(4,:,:) = [];
% show the polygon locations
nColors = size(region_coordinates,3);
for k = 1:nColors
plot(region_coordinates(:,1,k),region_coordinates(:,2,k), ...
'w','linewidth',2)
end
This line performs a basic conversion from sRGB to L*a*b*. See rgb2lab().
lab_fabric = rgb2lab(fabric);
For other images, decide what color classes you intend there to be, select a sampling of pixels representative of each class, average them, and work from there. That said, I see no reason why this clustering-based approach would be particularly suitable to the given task, especially considering that the test image is certainly not representative of any actual process image. It would be a waste of time to focus on optimizing the reliability of segmenting images which are never going to be used for anything.
I'm pretty sure I've seen other segmentation examples on the forum which used that same image, though perhaps none which used such a thoroughly mutilated copy as that one.

Community Treasure Hunt

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

Start Hunting!