matlab invert image
To invert an image in MATLAB, you can use the imcomplement
function. Here's an example of how to do it:
% Read the image
image = imread('your_image.jpg');
% Invert the image
inverted_image = imcomplement(image);
% Display the original and inverted images
subplot(1,2,1);
imshow(image);
title('Original Image');
subplot(1,2,2);
imshow(inverted_image);
title('Inverted Image');
In this code, we first read the image using the imread
function and store it in the variable image
. Then, we use the imcomplement
function to invert the image and store the result in the variable inverted_image
. Finally, we display both the original and inverted images using the imshow
function and provide appropriate titles for each subplot.
Note that you need to replace 'your_image.jpg'
with the path or filename of your actual image. Also, make sure to have the Image Processing Toolbox installed in MATLAB, as the imcomplement
function is part of this toolbox.
By following these steps, you should be able to invert an image in MATLAB.