zoukankan      html  css  js  c++  java
  • Matlab基础:关于图像的基本操作

    --

    %% 学习目标:学习关于图像的基本操作
     
    %% 通过抖动来增强图像的的色彩对比度
    clear all;
    close all;
    I = imread('cameraman.tif');%读取灰度图像
    BW = dither(I);%通过抖动转换为二值图像来增强图像的色彩对比度
    subplot(1,2,1);%将多个图片显示在同一个窗口,subplot(m,n,p)。
    imshow(I);
    subplot(1,2,2);
    imshow(BW);
     
    %% 获取图像信息
    clear all;
    close all;
    info = imfinfo('trees.tif','tif');%获取图像信息
    disp(info);%输出图像信息
     
    %% 改变图像格式
    clear all;
    close all;
    RGB = imread('trees.tif','tif');%读取一个RGB图片
    imwrite(RGB,'Mytrees.png','png');%将tif格式图片转换为png格式
    tupian = imread('Mytrees.png');
    figure;
    imshow(tupian);
     
    %% 读取图像中的某些帧
    clear all;
    close all;
    I1 = imread('mri.tif',5);%读取第5帧
    I20 = imread('mri.tif',25);
    figure;
    subplot(1,2,1);
    imshow(I1);
    subplot(1,2,2);
    imshow(I20);
     
    %% which mri.tif 查看图像位置
     
    %% 同时显示多帧图像
    clear all;
    close all;
    mri = uint8(zeros(128,128,1,25));
    for i = 1:25  %25帧
        [mri(:,:,:,i),map] = imread('mri.tif',i);
    end
    montage(mri,map);%同时显示多帧图像
     
    %% 将多帧图像转换为电影
    clear all;
    close all;
    mri = uint8(zeros(128,128,1,25));
    for i = 1 : 25
        [mri(:,:,:,i),map] = imread('mri.tif',i);
    end
    mov = immovie(mri,map);%把图像转换为动画
    implay(mov);%显示动画
     
    %% 图像相加  如果大于255就设置为255
    clear all;
    close all;
    I = imread('rice.png');
    J = imread('cameraman.tif');
    K = imadd(I,J,'uint16');
    imshow(K,[]);
     
    %% 图像相减,小于0则设置为0,  0到255  减去一个常数颜色更深
    clear all;
    close all;
    I = imread('cameraman.tif');
    J = imsubtract(I,90);%减去90  减的越大,图像越暗(0表黑色嘛)
    imshow(J);
     
    %% 图像相乘
    clear all;
    close all;
    I = imread('cameraman.tif','tif');
    J = immultiply(I,0.6);%乘0.6(小于1),变暗
    subplot(121);
    imshow(I);
    subplot(122);
    imshow(J);
     
    %% 图像相除  维数要一样
    clear all;
    close all;
    X = uint8([222 50 21; 56 77 89]);%X and Y 都是2*3的矩阵
    Y = uint8([66 66 66; 66 66 66]);
    Z = imdivide(X,Y);% X/Y
    disp(Z);
     
    %% 两幅图像的绝对差异
    clear all;
    close all;
    I = imread('cameraman.tif','tif');
    J = uint8(filter2(fspecial('gaussian'),I)); % 对图像进行滤波
    K = imabsdiff(I,J);%获取滤波图像和之前图像的差异
    subplot(121);
    imshow(I);
    subplot(122);
    imshow(K,[]);%加[]是为了显示清晰
     
    %% fspecial:用于建立预定义的滤波算子或者说产生预定义滤波器

    原文:https://blog.csdn.net/KimLK/article/details/78064384

    --

  • 相关阅读:
    小程序开发为何使用RPX
    C#判断网址是否可以访问
    [golang]go语言的channel学习
    tensorflow中图像增强的方法详解
    kaggle无法下载数据集解决办法
    keras模型中的model.fit()和model.fit_generator()的区别
    Keras.metrics中的accuracy总结
    Python 字符串前面加u,r,b,f的含义
    损失函数:binary_crossentropy、categorical_crossentropy、sparse_categorical_crossentropy
    jupyter代码自动补全
  • 原文地址:https://www.cnblogs.com/Ph-one/p/11516811.html
Copyright © 2011-2022 走看看