logo

Color Segmentation in MATLAB: A Step-by-Step Guide to Image Analysis and Object Labeling

   

Added on  2023-04-25

15 Pages4681 Words205 Views
Answer 1-c:
For specific “createMask.m” that function is helping in the identification of bat and ball is created
using color thresholder application of matlab. For creating this function first, you have to load
your image in the workspace of matlab using “imread’ function. After loading the image, you
can see your image in the workspace in the matrix form. Now open the color thresholder app
from the matlab tool bar in the image processing and computer vision tool box option or you can
open the application using “colorThresholder” command in the command window of matlab.
After that an application will open, click on “load image” option on the tool bar of the
application and select “from workspace” option, a small pop up window will open in which you
can select your image which is in the workspace in the form of matrix (true color version). After
selection of your image you will get the option to choose the color space so as per our
requirements, we need to work in L*a*b color space, select the L*a*b color space in the color
space selection option.
After selection of color space app opens the image with set of different controls for each color
component of the image. For L*a*b color space the application also shows the histograms which
represents the color components of the image. In this specific color space three histogram will
appear on the right side of the window of the app “L”, which indicated the brightness of the
image second ‘a’ which represents the red-green coordinates of the image and last ‘b’ which
represent the yellow-blue coordinates of the image. You can perform segmentation using the

slider controller of the histogram and by moving them across the spectrum. As we need to create
mask for the bat and ball so we used the draw button to select the ball and bat from the image,
after selecting the bat and all or can say region of interest from the image, the color thresholder
automatically thresholds the image based on the color selected in the region you draw . Also, the
color changes to reflect the segmentation, although the automatic thresholding does not segment
the part properly but you can refine the part using the histogram controls.
And in the image above you can see the minimum and maximum value of threshold, you can
change it accordingly to more refine the results. After the whole process when you got your
desired result you can save the code as well as results by using the export option of the
application. You can use that function by passing and RGB image and this function will create a
mask for the desired ROI without using the application.
Answer 1-d
Labeling-:

1) First important part of labeling to identify the pixel connectivity in the image, pixel
connectivity defines which pixel is connected with the other pixel of the image. Selecting
the connectivity is core part to identify the pixel connectivity. There two main
connectivity type 4 and 8. following table describes about the connectivity.
2) Second step is to convert the RGB image to gray scale and then in binary. A binary image
is required that has value of 1 (white) for all pixel in the input image with luminance
greater than variance and 0 (black) for all other pixel.
3) Now everything is ready for labeling the binary Image that is result of previous level.
Type of Connectivity has been mentioned before can be used in this stage to label our
Image.
4) General procedure is as follows-:
Run-length encodes the input image.
Scan the runs, assigning preliminary labels and recording label equivalences in a
local equivalence table.
Resolve the equivalence classes.

Relabel the runs based on the resolved equivalence classes.
5) This whole algorithm is the part of bwlabel function of matlab, by default the
connectivity setting of function is 8. This function returns label matrix that contains
labels for the 8-connected objects found in binary image.
Answer 1-e
For this specific part we used the “regionprop” function of matlab. Before this step we had
identified the label of each object, so we know the label of each label like the label =2 is for ball
and label =3 is for bat, similarly for other objects in the image. Now how the regionprop function
works. A label matrix which contains the label for each object in the image is passed through the
regionprop function. Element of L equals to 1 is belongs to the first object of the figure or image
and element of matrix L equal to 2 is belongs to the second object of the image and so on. The
question which property is used to identify the bat and ball as you can see in the property table
the orientation and the major, minor axis length are the defining property for the identification of
the objects. Angle between the x-axis and the major axis of the ellipse that has the same second-
moments as the region, returned as a scalar. The value is in degrees, ranging from -90 degrees to
90 degrees.
Answer 1-f
So, the region prop function is the main part of this property finding step of the code. Region
prop function works on the basis of L matrix that is labelled matrix calculated using the above
described algorithm, using regionprop function we can calculate the centroid, major axis, minor
axis, area etc. In the regionprop function either you can define each property separately or you
can use “all” property to calculated various properties of the objects based present in the labeled
matrix. Second part is the for loop, in the for loop basically we are just putting the label of the
image in the centroid of each object. As we have calculated the object’s centroid so we used
centroid property to put the label on the object.
Answer 2-b

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Color Thresholding and Region Properties for Object Detection in Matlab
|14
|4681
|271

Georectification: A Study on Using Erdas Imagine for Spatially Accurate Mapping
|18
|1692
|48