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)
Show older comments
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')
0 Comments
Answers (1)
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);
See Also
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!