How can I fit a line to a color joint histogram?

1 回表示 (過去 30 日間)
Kyuhee Jo
Kyuhee Jo 2020 年 3 月 15 日
回答済み: Pranjal Kaura 2021 年 9 月 29 日
Hi, in the photos like the right, I need to fit a line that approximates the yellowish color region. (Not like this green triangle, but one line that goes through the yellow region of the photo above. The file format is .fig and I have both picture on the left and right in the .fig file.
And I really don't have any idea.
Any help?

回答 (1 件)

Pranjal Kaura
Pranjal Kaura 2021 年 9 月 29 日
Hey Kyuhee,
It is my understanding that you want to identify yellow region in your image and fit a line that best approximates it's location.
Identification of the yellow region can be done using the following steps:
  1. Extracting the RGB channels in the image (Assuming RGB file format):
channel_Red = image(:, :, 1);
channel_Green = image(:, :, 2);
channel_Blue = image(:, :, 3);
2. Thresholding the required channels. Herein we need to identify yellow, thus you could try thresholding the Red and Green channels. A simple 'and' statement between the 2 binarized outputs can be taken to identify regions of yellowish tones.
BW_Red = im2binarize(channel_Red, threshold_Red);
BW_Green = im2binarize(channel_Green, threshold_Green);
3. Identifying the ROI (Region of Interest) in the binarized ouput. This will generate a rectangular bounding box around the ROI.
regionprops(BW, 'BoundingBox');
Co-ordinates and dimensions of the bounding box can then be extracted and used to generate the corner points of the required line segment (These will be the 2 opposite corner points of the rectangle). To insert the line in the image, you can use the 'InsertShape' function.
You can also refer to the answers here and here for more help.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by