BÀI TẬP CHƯƠNG 2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

BÀI TẬP CHƯƠNG 2

 Read image to Matlab


%read image
I=imread('C:\Users\ADMIN\Downloads\XLA_CN_image_data_examples\
XLA_CN_image_data_examples\multi_face_color_segmentation.jpg');

 Show the image to figure


%show image to figure
figure;
imshow(I);

 Extract R,G,B channel


%extract R, G, B
I_red=I(:,:,1);
I_green=I(:,:,2);
I_blue=I(:,:,3);
 Show original image, R,G,B channel in the same figure
%show original,R,G,B in same figure
figure;
subplot(2,2,1) original image red image
imshow(I)
title('original image')

subplot(2,2,2)
imshow(I_red)
title('red image')

subplot(2,2,3)
imshow(I_green)
title('green image')
green image blue image

subplot(2,2,4)
imshow(I_blue)
title('blue image')

 Crop image
%crop image
I_crop=imcrop(I,[72 68 100 100]);
figure;
imshow(I_crop);

 Find maximum value of pixel


%maximum pixel & find position
max_red = max(max(I_red));
[max_red_x, max_red_y] = find(I_red == max_red);

 Find minimum value of pixel


%%minimum pixel & find position
min_red = min(min(I_red));
[min_red_x, min_red_y] = find(I_red == min_red);
 Find position
figure;
imshow(I_red);hold on;
plot(min_red_y, min_red_x,'r.', 'linewidth',6);
plot(max_red_y, max_red_x,'g.', 'linewidth',6);
hold off;

 Increase the image intensity linear (multiply 2 times darker and


brighter)
%intensity change
I_red2 = 2*I_red;
I_red3 = 0.5*I_red;

figure;
subplot(1,3,1);
imshow(I_red);
title('red'); red intensity x2 intensity x0.5

subplot(1,3,2);
imshow(I_red2);
title('intensity x2');

subplot(1,3,3);
imshow(I_red3);
title('intensity x0.5');
 Subtract two images/find the difference of two images
%subtract image
I1= imread('C:\Users\ADMIN\Downloads\XLA_CN_image_data_examples\
XLA_CN_image_data_examples\circuit_no_defect.jpg');
I1_gray = rgb2gray(I1);
I2= imread('C:\Users\ADMIN\Downloads\XLA_CN_image_data_examples\
XLA_CN_image_data_examples\circuit_defect.jpg');
I2_gray = rgb2gray(I2);
figure;
imshow(I1_gray);
title('I1 gray');
figure;
imshow(I2_gray);
title('I2 gray');
I_sub = I1_gray-I2_gray;
figure;
imshow(I_sub);
title('I sub');

I1 gray I2 gray I sub

You might also like