Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

How can I invert a binary image in MATLAB?

Date: 2023-01-06 13:54:59

I have a binary image and need to convert all of the black pixels to white pixels and vice versa. Then I need to save the new image to a file. Is there a way to do this without simply looping over every pixel and flipping its value? 

Answers:

If you have a binary image binImage with just zeroes and ones, there are a number of simple ways to invert it:

 

binImage = ~binImage;
binImage = 1-binImage;
binImage = (binImage == 0);

Then just save the inverted image using the function IMWRITE.


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com