How to extract the region coordinates in this example?
16 ビュー (過去 30 日間)
古いコメントを表示
In this example for color segmentation we are given a .MAT file named regioncoordinates.
Citing the example: "Your approach is to choose a small sample region for each color and to calculate each sample region's average color in 'a*b*' space. You will use these color markers to classify each pixel.
To simplify this example, load the region coordinates that are stored in a MAT-file."
How do i go about getting the region coordinates?
0 件のコメント
採用された回答
Image Analyst
2023 年 12 月 29 日
Use load to load the (x,y) coordinates from the MAT file. Then you can use poly2mask to get a mask then use the mask to get the mean a and b. Basically
s = load(matFileName)
x = s.x; % Example if there is only a single region in the mat file
y = s.y;
mask = poly2mask(x, y, rows, columns); % Create a binary image from the list of (x,y) coordinates.
labImage = rgb2lab(rgbImage); % Get reference image into LAB color space
[lImage, aImage, bImage] = imsplit(labImage); % Separate into separate channels.
% Get mean of each channel inside the mask region only.
meanL = mean(lImage(mask))
meanA = mean(aImage(mask))
meanB = mean(bImage(mask))
Do that for all regions that you have. Now to classify each pixel of an image according which color is closest you need to compute the Delta E color difference. See deltaE. You'll have one delta E image for each region. Which ever delta E region is smallest is the color that that region should be classified as. For example if you have a red region and a blue region, and if a pixel is orange, then the delta E from the red might be 5 but the delta E from the blue might be 20. So that orange pixel would be classified as red because the color difference (distance) to the red mean is closer to red than to blue (the delta E red is less than the delta E blue).
Of course you need the reference image from which you will measure the reference color patches, and then you'll need some other image for which you will classify every pixel according to which color is closest.
For an alternative classification scheme, Discriminant Analysis, see attached demo. It's done in RGB color space but of course you could do it in LAB color space too with appropriate changes.
If you have any trouble, attach your mat file, reference image, and test image to be classified with the paperclip icon.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Image Segmentation and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!