Some basic image processing examples with MATLAB.
Enhance contrast using histogram equalization. Input: grayscale image. Output: adjusted image.
Adjust image intensity values.
Finding the negative of an image by changing the intensity levels of the pixels present in the image.
Checks if image is either grayscale or RGB, and depends on statement choose loop. Works good on grayscale images but slow on RGB.
if size(image,3) == 1
[n,m] = size(image);
for i = 1:n
for j = 1:m
image_negative(i,j) = 255 - image(i,j);
end
end
subplot(1,2,2);
imshow(image_negative), title('Negative');
elseif size(image,3) == 3
[n,m,p] = size(image);
for i = 1:n
for j = 1:m
for k = 1:p
image_negative(i,j,k) = 255 - image(i,j,k);
end
end
end
subplot(1,2,2);
imshow(image_negative), title('Negative');
end
We can also get the negative of an image using MATLAB's built-in function imcomplement(). It subtracts the pixel value from the maximum pixel value of the image class.
Converting grayscale image to binary (black and white) image.
Converting RGB image to binary.