0
votes

I have a binary image which I used bwconncomp and regionprops on to divide into regions of interest. I have a line of pixels which I want to lay across the binary image...and find which region of interest/connected component has the most line pixels in it. So in the attached image I use bwconncomp on bwimage, I get components 1,2,3. Then I have a list of pixels corresponding to the blue line. I want to find which connected component has the most of the blue line in it (#1).

I imagine its something like...

line=(some pixel values);
cc=bwconncomps(bwimage);
tempvar=[];

for i=1:length(bwconncomps)
     tempvar=find(cc.PixelIdxList{i}==line);
end

[~ answer]=max(tempvar);

1

1 Answers

0
votes

You can use ismember to determine how many items in PixelList occur in your list of pixels that lie along the line. Then you can use max to identify the component that has the most.

% Indices of pixels that are along the line of interest
linePixels = [1, 2, 3, 4, ...]  

% Determine the number of pixels within each component that are on this line
nPerComponent = cellfun(@(inds)sum(ismember(inds, linePixels)), {cc.PixelIdxList});

% Find the component with the most points on this line
[~, answer] = max(nPerComponent);