how can I remove the regions in the edge map that are partially blocked along a line of sight of the centroid?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Image Analyst
2020-2-10
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);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Denoising and Compression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!