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


    本文系《数字图像处理原理与实践(MATLAB版)》一书之代码系列的Part1(P1~42)。代码运行结果请參见原书配图。


     

    P20

     

    I = imread('lena.jpg');
    BW1 = im2bw(I);
    BW2 = im2bw(I, 0.3);
    BW3 = im2bw(I, 0.6);
    figure
    subplot(2,2,1),imshow(I);
    title('original');
    subplot(2,2,2),imshow(BW1);
    title('default');
    subplot(2,2,3),imshow(BW2);
    title('level = 0.3');
    subplot(2,2,4),imshow(BW3);
    title('level = 0.6')

     

    P25-1

     

    IMG1 = imread('airplane.jpg');
    IMG2 = imread('baboon.jpg');
    IMG3 = imread('lena.jpg');
    imshow(IMG1)
    imshow(IMG2)
    imshow(IMG3)

     

    P25-2

     

    % figure
    imshow(IMG1)
    figure(5)
    imshow(IMG2)

     

    P26

     

    figure;
    subplot(1,2,1),subimage(IMG1);
    title('airplane');
    subplot(1,2,2),subimage(IMG2);
    title('baboon');

     

    P31

     

    imhist(I)
    imhist(I, n)
    [counts, x]=imhist(...)

     

    P32

     

    i = imread('theatre.jpg');
    g = rgb2gray(i);
    figure
    subplot(121), imhist(g);
    subplot(122), imhist(g, 64);

     

    P33

     

    i = imread('baboon.jpg');
    i = rgb2gray(i);
    [m,n]=size(i);
    [counts1, x]=imhist(i, 32);
    subplot(121), stem(x, counts1);
    counts2 = counts1/m/n;
    subplot(122), stem(x, counts2);

     

    P35

     

    i=imread('theatre.jpg');
    [x,y,z]=size(i);

    figure
    subplot(221), imshow(i);
    title('original image')

    %提取红色分量
    r=i;
    %r(:,:,1)=a(:,:,1);
    r(:,:,2)=zeros(x,y);
    r(:,:,3)=zeros(x,y);
    r=uint8(r);
    subplot(222),imshow(r);
    title('R-component-image')

    %提取绿色分量
    g=i;
    g(:,:,1)=zeros(x,y);
    %g(:,:,2)=a(:,:,2);
    g(:,:,3)=zeros(x,y);
    g=uint8(g);
    subplot(223),imshow(g);
    title('G-component-image')

    %提取蓝色分量
    b=i;
    b(:,:,1)=zeros(x,y);
    b(:,:,2)=zeros(x,y);
    %b(:,:,3)=a(:,:,3);
    b=uint8(b);
    subplot(224),imshow(b);
    title('B-component-image')

     

     P38

     

    i=imread('theatre.jpg');
    r=i(:,:,1);
    g=i(:,:,2);
    b=i(:,:,3);
    subplot(1,3,1), imhist(r), title('R component');
    subplot(1,3,2), imhist(g), title('G component');
    subplot(1,3,3), imhist(b), title('B component');


     

    P41

     

    i = imread('theatre.jpg');
    i = im2double(rgb2gray(i));
    [m,n]=size(i);

    %添加对照度
    Fa = 1.25; Fb = 0;
    O = Fa.*i + Fb/255;
    figure(1), subplot(221), imshow(O);
    title('Fa = 1.25, Fb = 0, contrast increasing');
    figure(2),subplot(221), [H,x]=imhist(O, 64);
    stem(x, (H/m/n), '.');
    title('Fa = 1.25, Fb = 0, contrast increasing');

    %减小对照度
    Fa =0.5; Fb = 0;
    O = Fa.*i + Fb/255;
    figure(1), subplot(222),imshow(O);
    title('Fa = 0.5, Fb = 0, contrast decreasing');
    figure(2), subplot(222), [H,x] = imhist(O, 64);
    stem(x, (H/m/n), '.');
    title('Fa = 0.5, Fb = 0, contrast decreasing');

    %线性亮度添加
    Fa = 0.5; Fb = 50;
    O = Fa.*i + Fb/255;
    figure(1), subplot(223), imshow(O);
    title('Fa = 0.5, Fb = 50, brightness control');
    figure(2), subplot(223), [H,x]=imhist(O,64);
    stem(x, (H/m/n), '.');
    title('Fa = 0.5, Fb = 50, brightness control');

    %反相显示
    Fa = -1; Fb = 255;
    O = Fa.*i + Fb/255;
    figure(1), subplot(224), imshow(O);
    title('Fa = -1, Fb = 255, reversal processing');
    figure(2), subplot(224),[H,x]=imhist(O, 64);
    stem(x, (H/m/n), '.');
    title('Fa = -1, Fb = 255, reversal processing');

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


  • 相关阅读:
    加法图灵机
    Experiment 1
    进制转换
    快速排序
    辗转相除、线段交点、多角形面积公式
    JS如何优雅监听容器高度变化
    解决react和其他框架之间的交互问题
    MacBook Pro触控板手势
    代理 请求登录失效(显示未登录)问题
    Web端 长按事件
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7381072.html
Copyright © 2020-2023  润新知