Hi Warid!
I understand that you want to identify and analyse two specific types of pixels related to a ROI within an image outlined by a yellow boundary: one pixel on the boundary (C1) and another immediately outside the ROI, along a line extending from the ROI's centre through C1 (C2). To achieve your goal, you may follow these steps in MATLAB.
- Identify the Yellow Boundary : You'll need to convert your image to the HSV color space (or another appropriate space) to effectively isolate yellow colors.
yellowMask = (Ihsv(:,:,1) >= hueRange(1)) & (Ihsv(:,:,1) <= hueRange(2)) & ...
(Ihsv(:,:,2) >= saturationMin) & (Ihsv(:,:,3) >= valueMin);
yellowMask = imfill(yellowMask, 'holes');
yellowMask = bwareaopen(yellowMask, 50);
[B, ~] = bwboundaries(yellowMask, 'noholes');
2. Find Contours (Boundaries) of the Yellow Region:
boundaryLengths = cellfun(@(x) size(x, 1), B);
[~, largestBoundaryIndex] = max(boundaryLengths);
boundary = B{largestBoundaryIndex};
3. Calculate the Centroid of the ROI:
stats = regionprops(yellowMask, 'Centroid');
centroid = stats.Centroid;
error('No regions found. Check the binary mask and color thresholds.');
4. Find Boundary Pixel (C1) and Outward Neighbour (C2):
direction = [point(2) - centroid(1), point(1) - centroid(2)];
direction = direction / norm(direction);
C1 = I(point(1), point(2), :);
newPoint = round([point(2) + direction(1) * stepSize, point(1) + direction(2) * stepSize]);
newPoint(1) = max(min(newPoint(1), size(I, 2)), 1);
newPoint(2) = max(min(newPoint(2), size(I, 1)), 1);
C2 = I(newPoint(2), newPoint(1), :);
This script provides a basic framework. You might need to loop through all boundary points or select specific ones based on your requirements. Also, the color range for identifying yellow might require adjustment depending on the specific hues in your image. This approach assumes the yellow boundary is distinct and can be isolated with color thresholding. If the boundary is not clearly defined by color, you might need a more sophisticated method to identify the ROI.
For more information on some of the functions used in the above code, you can refer to these documentation links:
Hope this helps!