how can I remove the regions in the edge map that are partially blocked along a line of sight of the centroid?

1 view (last 30 days)
Dear All, how can I remove the regions in the edge map that are partially blocked along a line of sight of the center? For example, the outer regions(e.g. red,blue) should be removed. The bw image is in the attachments.
clc;
close all;
clear;
RBRresult = imread('C:\Users\tommy\Desktop\DATA\bwimg.bmp');
grayImage = uint8(RBRresult);
[rows, columns, numberOfColorChannels] = size(grayImage)
binaryImage = grayImage;
binaryImage = imclearborder(binaryImage);
% Label
[labeledImage, numBlobs] = bwlabel(binaryImage);
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
STATS = regionprops(binaryImage, 'centroid');
centroids = cat(1, STATS.Centroid);
cenX = centroids(1,1);
cenY = centroids(1,2);
figure(9),imshow( coloredLabels ) ,
hold on,plot(cenX,cenY,'MarkerSize',15,'Marker','*','LineStyle','none','Color',[1 0 0]);hold off;
imwrite(coloredLabels,'coloredLabels.bmp')

Answers (1)

Image Analyst
Image Analyst on 10 Feb 2020
To get rid of the red and blue blobs, you need to identify which blob contains the right most, and top most, pixels. So simply get all the pixels in each blob by asking regionprops() for 'PixelList', and then use ismember() to find out which blob contains the topmost and right most column. Untested code
[labeledImage, numBlobs] = bwlabel(binaryImage);
STATS = regionprops(labeledImage, 'centroid', 'PixelList');
[rows, columns] = find(binaryImage);
rightColumnX = max(columns);
topRowY = min(rows);
numBlobs = length(STATS)
blobsToKeep = true(1, numBlobs);
for k = 1 : numBlobs
if ismember(rightColumnX, STATS(k).PixelList(:, 1))
blobsToKeep(k) = false;
end
if ismember(topRowY, STATS(k).PixelList(:, 2))
blobsToKeep(k) = false;
end
end
% Convert from logical to index numbers.
blobsToKeep = find(blobsToKeep);
% Get new binary image.
binaryImage = ismember(labeledImage, blobsToKeep);
  1 Comment
tl423
tl423 on 10 Feb 2020
Thanks for answering, but my question may be not clear. Let me ask in other way. If I draw a line to a region R1 from center in the edge map(the yellow line in new image in the attachment) and the line is blocked by another region, R1 should be removed. For example, the pink region is blocked by the light green region, so the pink region should be removed. How to removed those outer regions based on the above condition? Thank you.

Sign in to comment.

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!