Remove black pixels from RGB image

Technical Source
2 min readJan 31, 2023

--

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:

% define scale bar:
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;
% cropped and screwed: 
I = imcrop(firstFrame, roi_Bar);
figure;
imshow(I);
% remove black border:
mask = (I(:, :, 1) == 0) & (I(:, :, 2) == 0) & (I(:, :, 3) == 0);
I(mask) = [];
figure;
imshow(I); % this returns a horrific result

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

All black pixels cannot be removed since the image must remain rectangular. You can remove whole rows or whole columns, but not randomly scattered isolated groups of black pixels. With that colorbar image you have, you could delete everything up to and including the black outline of the colormap. Is that what you want to do?

Deleting everything up to and including the black outline would be great.

Then Wait, the pseudocolored thermal picture you attached is nothing like the small color bar image inserted into the body of your message. So let me get this straight. You want just the color bar itself, without the black outline around it and without any other stuff in the scene — just the color bar alone, right? And do you want the color bar cropped out to be its own output image?

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet