Second week homework
Article Directory
first question:
Select a photo in the folder, and use three sub-forms of a form to display the color image, gray-scale image, and histogram of the gray-scale image.
Code:
clc,clear all
A = imread("D:/图片1.jpg");
figure(1)
subplot(1,3,1);
imshow(A)
title('彩色图像')
B = rgb2gray(A);
subplot(1,3,2);
imshow(B)
title('灰度图像')
subplot(1,3,3)
imhist(B)
title('灰度图像直方图')
operation result:
The second question:
Write a program to perform point arithmetic transformation codes on all pixel values in color photos that meet the following conditions
:
clc,clear all
rgb = imread("D:/图片1.jpg");
R=rgb(:,:,1); %red
G=rgb(:,:,2); %green
B=rgb(:,:,3); %blue
[i,j,k]=size(rgb);
for x=1:i
for y=1:j
if( (R(x,y) > 150) && (G(x,y) >150) && (B(x,y) >150) )
R(x,y) = 0;
G(x,y) = 0;
B(x,y) = 255;
end
end
end
for x=1:i
for y=1:j
A(x,y,1) = R(x,y);
A(x,y,2) = G(x,y);
A(x,y,3) = B(x,y);
end
end
figure;
imshow(A)
operation result: