《数字图像处理原理与实践(MATLAB版)》一书之代码Part2[通俗易懂]

《数字图像处理原理与实践(MATLAB版)》一书之代码Part2

大家好,又见面了,我是全栈君。

本文系《数字图像处理原理与实践(MATLAB版)》一书之代码系列的Part2(P43~80),代码运行结果请參见原书配图,建议下载代码前阅读下文:

关于《数字图像处理原理与实践(MATLAB版)》一书代码公布的说明

 

http://blog.csdn.net/baimafujinji/article/details/40987807

P44

i = imread(‘theatre.jpg’);
i = rgb2gray(i);
i = double(i);

out1 = log(1+i)/0.065;
out2 = log(1+i)/0.035;
out1(find(out1>255)) = 255;
out2(find(out2>255)) = 255;
out1 = uint8(out1);
out2 = uint8(out2);

subplot(221), imshow(out1), title(‘image, p = 0.065’);
subplot(222), imhist(out1), title(‘histgram, p = 0.065’);
subplot(223), imshow(out2), title(‘image, p = 0.035’);
subplot(224), imhist(out2), title(‘histgram, p = 0.035’);

P47

i = rgb2gray(imread(‘theatre.jpg’));
i = double(i);
y1 = 255*(i/255).^2.5;
y2 = 255*(i/255).^0.4;
y1 = uint8(y1);
y2 = uint8(y2);
subplot(221), imshow(y1), title(‘p =2.5’);
subplot(222), imhist(y1), title(‘p =2.5’);
subplot(223), imshow(y2), title(‘p =0.4’);
subplot(224), imhist(y2), title(‘p =0.4’);

P48

i = rgb2gray(imread(‘theatre.jpg’));
y1 = double(i);
y1 = 255*(y1/255).^2.5;
y2 = uint8(y1);
y3 = imadjust(y2, [ ], [ ], 0.4);
subplot(131), imshow(i), title(‘original image’);
subplot(132), imshow(y2),title(‘power = 2.5’);
subplot(133), imshow(y3),title(‘gamma = 0.4’);

P49

i = imread(‘theatre.jpg’);
i = rgb2gray(i);
i = double(i);

y1 = 1.5.^(i*0.070)-1;
y2 = 1.5.^(i*0.050)-1;
y1(find(y1>255)) = 255;
y2(find(y2>255)) = 255;
y1 = uint8(y1);
y2 = uint8(y2);

subplot(221), imshow(y1), title(‘c=0.070’);
subplot(222), imhist(y1), title(‘c=0.070’);
subplot(223), imshow(y2), title(‘c=0.050’);
subplot(224), imhist(y2), title(‘c=0.050’);

P52

i = imread(‘theatre.jpg’);
i = rgb2gray(i);
L = imadjust(i,[ ],[50/255;150/255]);
J = imadjust(L,[50/255;150/255 ],[20/255;230/255]);
subplot(221), imshow(L), title(‘low contrast’);
subplot(222), imhist(L), title(‘low contrast’);
subplot(223), imshow(J), title(‘gray stretch’);
subplot(224), imhist(J), title(‘gray stretch’);

P54

i = rgb2gray(imread(‘theatre.jpg’));
LC = imadjust(i,[ ],[50/255;150/255]);
figure(1), subplot(221), imshow(LC);
title(‘low contrast’);
figure(1),subplot(222), imhist(LC);
title(‘low contrast’);
HE1 = histeq(LC);
figure(1), subplot(223), imshow(HE1);
title(‘histogram equalization’);
figure(1),subplot(224), imhist(HE1);
title(‘histogram equalization’);

P56

img = rgb2gray(imread(‘theatre.jpg’));
img_ref = rgb2gray(imread(‘rpic.jpg’));
[hgram, x] = imhist(img_ref);
J = histeq(img, hgram);
subplot(2,3,1), imshow(img), title(‘original image’);
subplot(2,3,4), imhist(img), title(‘original image’);
subplot(2,3,2), imshow(img_ref), title(‘reference image’);
subplot(2,3,5), imhist(img_ref), title(‘reference image’);
subplot(2,3,3), imshow(J), title(‘output image’);
subplot(2,3,6), imhist(J), title(‘output image’);

P64-1

I = imread(‘apostles.jpg’);
I = double(I);
B = zeros(size(I));
H = size(I);
move_x = 100;
move_y = 150;
B(move_y + 1:H(1), move_x+1:H(2), 1:H(3))=…
I(1:H(1)-move_y, 1:H(2) – move_x, 1:H(3));
subplot(1,2,1),subimage(uint8(I))
title(‘原图像’)
subplot(1,2,2),subimage(uint8(B))
title(‘平移变换’);

P64-2

I = imread(‘apostles.jpg’);
se=translate(strel(1),[150 100]);
B = imdilate(I,se);
figure;
subplot(1,2,1),subimage(I);
title(‘原图像’);
subplot(1,2,2),subimage(B);
title(‘平移变换’);

P66

I = imread(‘apostles.jpg’);
[height, width, dim]=size(I);
%水平镜像变换
tform = maketform(‘affine’,[-1 0 0;0 1 0; width 0 1]);
B=imtransform(I, tform, ‘nearest’);
%垂直镜像变换
tform2 = maketform(‘affine’, [1 0 0; 0 -1 0; 0 height 1]);
C=imtransform(I, tform2, ‘nearest’);
subplot(1,3,1),imshow(I);
title(‘原图像’);
subplot(1,3,2),imshow(B);
title(‘水平图像’);
subplot(1,3,3),imshow(C);
title(‘垂直图像’);

P67

A = imread(‘apostles.jpg’);
A = double(A);
figure(1), imshow(uint8(A));
H = size(A);
figure(2),B(1:H(1),1:H(2),1:H(3))=A(H(1):-1:1,1:H(2),1:H(3));%垂直镜像
imshow(uint8(B));
figure(3),C(1:H(1),1:H(2),1:H(3))=A(1:H(1),H(2):-1:1,1:H(3));%水平镜像
imshow(uint8(C));

P69

I = imread(‘apostles.jpg’);
tform = maketform(‘affine’,[0 1 0; 1 0 0; 0 0 1]);%定义转置矩阵
B = imtransform(I, tform, ‘nearest’);
subplot(1,2,1),imshow(I)
title(‘原图像’);
subplot(1,2,2),imshow(B)
title(‘转置图像’);

P74

I = imread(‘C:\apostles.jpg’);
A = imresize(I, 1.5, ‘nearest’);
B = imresize(I, 1.5, ‘bilinear’);
C = imresize(I, 1.5, ‘bicubic’);
subplot(2,2,1), imshow(I), title(‘original’);
subplot(2,2,2), imshow(A), title(‘nearest’);
subplot(2,2,3), imshow(B), title(‘bilinear’);
subplot(2,2,4), imshow(C), title(‘bicubic’);

P80

I = imread(‘apostles.jpg’);
A = imrotate(I, 30, ‘nearest’);%旋转30度,最邻近插值
figure(1),imshow(A)
B = imrotate(I, 45, ‘bilinear’,’loose’);%旋转45度,二次线性插值
figure(2),imshow(B)


(代码公布未完,请待兴许…)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/116517.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 同一界面画出多个QQ图(R语言)「建议收藏」

    同一界面画出多个QQ图(R语言)「建议收藏」题目:一名研究者用光子吸收法测量了妇女骨骼中无机物含量,对三根骨头主侧和非主侧记录了测量值,数据框“T1bones.txt”中的第2至第7列记录了相应数据。对各个变量做qq图,在同一个界面画出所有的qq图,不同的qq图用不同颜色表示。文件:T1bones.txt受试者编号    主侧桡骨    桡骨    主侧肱骨    肱骨    主侧尺骨    尺骨1    1.103    1….

  • react的context用法_api接口源码

    react的context用法_api接口源码React中Context的API

  • win server 2008 R2 支持[通俗易懂]

    win server 2008 R2 支持[通俗易懂]win server 2008 R2 支持

  • linux下卸载apache方法小结

    linux下卸载apache方法小结

  • continue和break的区别与用法「建议收藏」

    continue和break的区别与用法「建议收藏」一般而言,程序进入循环后在下一次循环测试之间会执行完循环体的所以语句。continue和break语句可以根据循环体中测试结果来忽略一部分循环内容,甚至结束循环。continue语句三种循环都可以使用continue语句。执行到该语句时,会跳过本次迭代(即循环)的剩余部分,并开始下一轮迭代。如果continue语句在嵌套循环内,则只会影响包含该语句的内层循环。语法C语言中continue语句的语法:continue;流程图实例#inclu……

  • 最优化算法之粒子群算法(PSO)

    最优化算法之粒子群算法(PSO)一、粒子群算法的概念  粒子群优化算法(PSO:Particleswarmoptimization)是一种进化计算技术(evolutionarycomputation)。源于对鸟群捕食的行为研究。粒子群优化算法的基本思想:是通过群体中个体之间的协作和信息共享来寻找最优解.  PSO的优势:在于简单容易实现并且没有许多参数的调节。目前已被广泛应用于函数优化、神经网络训练、模糊系统控制…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号