数字图像处理(一)

 

测试环境:Win10+Matlab2018

1.随机生成灰度图

X = rand(25, 25);
Y = round(255*X);
class(Y)  %判断类型
Z = 255 - Y; %将灰度值进行反转
subplot(1,2,1)
imshow(uint8(Y))
xlabel('Y')
subplot(1,2,2)
imshow(uint8(Z))
xlabel('Z')

2.随机生成彩色图

rgb = rand(25,25,3)
Im_color = round(rgb*255);
figure(4)
size(Im_color)
class(Im_color)
imshow(uint8(Im_color))

3.读一幅图像,将颜色翻转再输出

B = imread('lighthouse.png');
C = 255 - B;
subplot(1,2,1)
imshow(B)
xlabel('B')
subplot(1,2,2)
imshow(C)
xlabel('C')

4.读图并绘制其直方图

Img = imread('lighthouse.png');
Img = rgb2gray(Img);

count = tabulate(Img(:)); %统计灰度值的频率[灰度值;频率;百分比]
temp = count(:,2);
[c,m] = max(temp); %找到频率最大的灰度值

subplot(1,2,1)
imshow(Img)
xlabel('灰度图')
subplot(1,2,2)
bar(count(:,2))
text(m,temp(m),num2str(m),'VerticalAlignment','bottom',...
'HorizontalAlignment','center','FontSize',9,'color','r','FontWeight','bold')
xlabel('灰度直方图')

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值