I know that variations of this question get asked a lot on here, but I haven't found a solution that works for my problem very well.
How do I remove the black border from the image above programmatically, but not by using imcrop!? I would prefer to find & remove all of the black pixels in the image, by effectively deleting that data--leaving me with a (yes) cropped image that contains only the color region of this image. My attempt is as follows:
firstFrame = read(vidObj,1);
imshow(firstFrame,'InitialMagnification',300);
title('Define the scale bar region:','FontSize',16);
scaleBar = drawrectangle('Color',[1 1 0]);
roi_Bar = scaleBar.Position;
I = imcrop(firstFrame, roi_Bar);
figure;
imshow(I);
mask = (I(:, :, 1) == 0) & (I(:, :, 2) == 0) & (I(:, :, 3) == 0);
I(mask) = [];
figure;
imshow(I);
Many thanks in advance!
2 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/717585-remove-black-pixels-from-rgb-image#comment_1264745
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/717585-remove-black-pixels-from-rgb-image#comment_1264745
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/717585-remove-black-pixels-from-rgb-image#comment_1265745
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/717585-remove-black-pixels-from-rgb-image#comment_1265745
Sign in to comment.