完成实验一、二
This commit is contained in:
parent
6c28bf7104
commit
3079d4bf44
61
EXP_one.m
Normal file
61
EXP_one.m
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
% 读取图片
|
||||||
|
image = imread('test.jpg');
|
||||||
|
|
||||||
|
% 灰度化处理
|
||||||
|
image_gray = rgb2gray(image);
|
||||||
|
|
||||||
|
% 二值化处理
|
||||||
|
image_imbinarize = imbinarize(image_gray);
|
||||||
|
|
||||||
|
% 降采样处理
|
||||||
|
n = 2;
|
||||||
|
m = 4;
|
||||||
|
image_sample2 = image(1:n:end, 1:n:end,:);
|
||||||
|
image_sample4 = image(1:m:end, 1:m:end,:);
|
||||||
|
|
||||||
|
% 图像叠加
|
||||||
|
image_2 = imread('photo.jpg');
|
||||||
|
image_add = imadd(image, image_2);
|
||||||
|
|
||||||
|
% 亮度增加
|
||||||
|
image_light = imadjust(image, [0 0 0; 0.5 0.5 0.5],[]);
|
||||||
|
|
||||||
|
% 反转颜色
|
||||||
|
image_reversal = imadjust(image , [0 0 0; 1 1 1], [1 1 1; 0 0 0]);
|
||||||
|
|
||||||
|
% 展示照片
|
||||||
|
figure;
|
||||||
|
subplot(1,3,1);
|
||||||
|
imshow(image);
|
||||||
|
title('Original Image'); % 原图
|
||||||
|
subplot(1,3,2);
|
||||||
|
imshow(image_gray);
|
||||||
|
title('Grayed Image'); % 灰度化图像
|
||||||
|
subplot(1,3,3);
|
||||||
|
imshow(image_imbinarize);
|
||||||
|
title('Binary Image'); % 二值化图像
|
||||||
|
|
||||||
|
figure;
|
||||||
|
subplot(1,3,1);
|
||||||
|
imshow(image);
|
||||||
|
title('Original Image'); % 原图
|
||||||
|
subplot(1,3,2);
|
||||||
|
imshow(image_sample2);
|
||||||
|
title('2x Down Sampling'); % 2倍降采样
|
||||||
|
subplot(1,3,3);
|
||||||
|
imshow(image_sample4);
|
||||||
|
title('4x Down Sampling'); % 4倍降采样
|
||||||
|
|
||||||
|
figure;
|
||||||
|
subplot(2,2,1);
|
||||||
|
imshow(image);
|
||||||
|
title('Original Image'); % 原图
|
||||||
|
subplot(2,2,2);
|
||||||
|
imshow(image_add);
|
||||||
|
title('Overlay Image'); %图像叠加
|
||||||
|
subplot(2,2,3);
|
||||||
|
imshow(image_light);
|
||||||
|
title('Brightness Increase'); %亮度增加
|
||||||
|
subplot(2,2,4);
|
||||||
|
imshow(image_reversal);
|
||||||
|
title('Color Inversion'); %颜色反转
|
79
EXP_two.m
Normal file
79
EXP_two.m
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
% 读取图片
|
||||||
|
image = imread('test.jpg');
|
||||||
|
|
||||||
|
% 灰度化处理
|
||||||
|
image_gray = rgb2gray(image);
|
||||||
|
|
||||||
|
% RGB色彩分离
|
||||||
|
red = image(:, :, 1);
|
||||||
|
green = image(:, :, 2);
|
||||||
|
blue= image(:, :, 3);
|
||||||
|
|
||||||
|
image_red = cat(3, red, zeros(size(red), 'uint8'), zeros(size(red), 'uint8'));
|
||||||
|
image_green = cat(3, zeros(size(green), 'uint8'), green, zeros(size(green), 'uint8'));
|
||||||
|
image_blue = cat(3, zeros(size(blue), 'uint8'), zeros(size(blue), 'uint8'),blue);
|
||||||
|
|
||||||
|
% 均衡化处理
|
||||||
|
red_eq = histeq(red);
|
||||||
|
green_eq = histeq(green);
|
||||||
|
blue_eq = histeq(blue);
|
||||||
|
|
||||||
|
image_eq = cat(3, red_eq, green_eq, blue_eq);
|
||||||
|
|
||||||
|
% 展示照片
|
||||||
|
figure;
|
||||||
|
subplot(2,2,1);
|
||||||
|
imshow(image);
|
||||||
|
title('Original Image'); %原图
|
||||||
|
subplot(2,2,2);
|
||||||
|
imshow(image_red);
|
||||||
|
title('Red Channel'); %红色通道
|
||||||
|
subplot(2,2,3);
|
||||||
|
imshow(image_green);
|
||||||
|
title('Green Channel'); %绿色通道
|
||||||
|
subplot(2,2,4);
|
||||||
|
imshow(image_blue);
|
||||||
|
title('Blue Channel'); %蓝色通道
|
||||||
|
|
||||||
|
figure;
|
||||||
|
ax1 = subplot(2,2,1);
|
||||||
|
imshow(image_gray);
|
||||||
|
colormap(ax1, gray);
|
||||||
|
title('Original Image'); %原图
|
||||||
|
ax2 = subplot(2,2,2);
|
||||||
|
imagesc(image_gray);
|
||||||
|
colormap(ax2, hsv);
|
||||||
|
colorbar;
|
||||||
|
title('Hsv'); %Hsv
|
||||||
|
ax3 = subplot(2,2,3);
|
||||||
|
imagesc(image_gray);
|
||||||
|
colormap(ax3, autumn);
|
||||||
|
colorbar;
|
||||||
|
title('Autumn'); %Autumn
|
||||||
|
ax4 = subplot(2,2,4);
|
||||||
|
imagesc(image_gray);
|
||||||
|
colormap(ax4, copper);
|
||||||
|
colorbar;
|
||||||
|
title('Copper'); %Copper
|
||||||
|
|
||||||
|
figure;
|
||||||
|
subplot(1,2,1);
|
||||||
|
imshow(image);
|
||||||
|
title('Original Image'); %原图
|
||||||
|
subplot(1,2,2);
|
||||||
|
imhist(image);
|
||||||
|
title('Histogram'); %直方图
|
||||||
|
|
||||||
|
figure;
|
||||||
|
subplot(2,2,1);
|
||||||
|
imshow(image);
|
||||||
|
title('Original Image'); %原图
|
||||||
|
subplot(2,2,2);
|
||||||
|
imshow(image_eq);
|
||||||
|
title('Equalization'); %均衡化
|
||||||
|
subplot(2,2,3);
|
||||||
|
imhist(image);
|
||||||
|
title('Original Histogram'); %原图直方图
|
||||||
|
subplot(2,2,4);
|
||||||
|
imhist(image_eq);
|
||||||
|
title('Equalization Histogram'); %均衡化直方图
|
Loading…
x
Reference in New Issue
Block a user