How do I make all pixels under an assisted line boundary = 1?
2 次查看(过去 30 天)
显示 更早的评论
I have manually segmented an image into two halves using:
roi = drawassisted('Closed',false);
Im = createMask(roi);
The generated mask (Im) is attached as an image
I want to make all pixels below that line = 1
The problem I am having is that the boundary sometimes loops back on itself, so x values are not unique, meaning I can't write a simple if statement using the pixel co-ordinates.
I'm sure the solution is quite easy, but I am really struggling to find it.
Any help much appreciated,
Thank you
0 个评论
采纳的回答
Image Analyst
2020-11-17
Try this (untested) with your mask to create a mask where the lower portion is true and the upper portion is false.:
[rows, columns] = size(mask); % Get size of your binary image with the line in it.
lastRow = ones(1, columns); % Initialize to top of image.
% Initialize a lower mask
lowerMask = false(rows, columns);
% Scan columns finding the last
for col = 1 : columns
thisColumn = mask(:, col);
t = find(thisColumn, 1, 'last');
if ~isempty(t)
lastRow(col) = t;
end
lowerMask(lastRow(col) : end, col) = true;
end
imshow(lowerMask);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!