Matching a curve to a specific color area in Matlab

I am trying to fit a curve on a specific area of ​​an image using the color of the pixels. As shown in the figure ( https://db.tt/PcxHGbT3 ), the image has a gray color that can be detected by image processing in Matlab. Once I found the position of the pixels using the following code in Matlab:

im = imread('layer.jpg');
figure,imshow(im);title('Original Image');
[y,x] = find(all(im<100, 3));

I need to find the position of the points located on the center line of the area shown in the image ( https://db.tt/PcxHGbT3 ), I thought I could fit the curve somehow, but I have no idea how I can do this in Matlab . Is there a shorter way besides processing all points?

+4
source share
2 answers

Can you use im2bw (im, 100/256) to the image threshold and bwmorph (BW, 'thin', INF) to reduce the result?

0
source

You can use binary image operations in Matlab to obtain centroids of dots with a gray area. With centroids, you can do anything with them, for example. fitting lines. This is one example based on your image of how this can be done.

% convert rgb to gray scale
im = rgb2gray(imread('layer.jpg'));

% mask of gray-color with points
bwMask1 = im < 100; 

% mask with points only
bwMask2 = im < 20;  

% remove points outside gray area
bwMask3 = bwareaopen(bwMask1, 400);

% points only withing gray ![enter image description here][1]area
bwMask4 = bwMask2 & ~(bwMask3 - bwMask2);

% label all points
[L] = bwlabel(bwMask4, 8);

% calculate points parameters
pointStats = regionprops(L);

% get centroids of each point
pointCentroidsCell = {pointStats(:).Centroid};
pointCentroidsMat  = vertcat(pointCentroidsCell{:});


%plot results:
RGB = label2rgb(L); 
figure, imshow(RGB); title('labeled points');
![enter image description here][2]
figure,imshow(im); hold on;
plot(pointCentroidsMat(:, 1), pointCentroidsMat(:, 2), 'r*');
title('Found centroinds');

enter image description hereenter image description here

0
source

All Articles