• Matlab 伪彩色 grayscale to rgb


    目标是伪彩色显示病灶区域。。

    希望效果是这样的。。看起来很特别。。吧。。

    Matlab shows both grayscale and RGB

    image overlay

    参考link:

    (1)matlab-show-colorbar-of-a-grayscale-image-in-a-figure-containing-a-rgb-image

    http://stackoverflow.com/questions/16403014/matlab-show-colorbar-of-a-grayscale-image-in-a-figure-containing-a-rgb-image

    (2)image-overlay-using-transparency

    http://blogs.mathworks.com/steve/2009/02/18/image-overlay-using-transparency/

    在这里存档一下grayscale to rgb部分的代码。。

    function res = grs2rgb(img, map)
    
    %%Convert grayscale images to RGB using specified colormap.
    %    IMG is the grayscale image. Must be specified as a name of the image 
    %    including the directory, or the matrix.
    %    MAP is the M-by-3 matrix of colors.
    %
    %    RES = GRS2RGB(IMG) produces the RGB image RES from the grayscale image IMG 
    %    using the colormap HOT with 64 colors.
    %
    %    RES = GRS2RGB(IMG,MAP) produces the RGB image RES from the grayscale image 
    %    IMG using the colormap matrix MAP. MAP must contain 3 columns for Red, 
    %    Green, and Blue components.  
    %
    %    Example 1:
    %    open 'image.tif';    
    %    res = grs2rgb(image);
    %
    %    Example 2:
    %    cmap = colormap(summer);
    %     res = grs2rgb('image.tif',cmap);
    %
    %     See also COLORMAP, HOT
    %
    %    Written by 
    %    Valeriy R. Korostyshevskiy, PhD
    %    Georgetown University Medical Center
    %    Washington, D.C.
    %    December 2006
    %
    %     vrk@georgetown.edu
    
    % Check the arguments
    if nargin<1
        error('grs2rgb:missingImage','Specify the name or the matrix of the image');
    end;
    
    if ~exist('map','var') || isempty(map)
        map = hot(64);
    end;
    
    [l,w] = size(map);
    
    if w~=3
        error('grs2rgb:wrongColormap','Colormap matrix must contain 3 columns');
    end;
    
    if ischar(img)
        a = imread(img);
    elseif isnumeric(img)
        a = img;
    else
        error('grs2rgb:wrongImageFormat','Image format: must be name or matrix');
    end;
    
    % Calculate the indices of the colormap matrix
    a = double(a);
    a(a==0) = 1; % Needed to produce nonzero index of the colormap matrix
    ci = ceil(l*a/max(a(:))); 
    
    % Colors in the new image
    [il,iw] = size(a);
    r = zeros(il,iw); 
    g = zeros(il,iw);
    b = zeros(il,iw);
    r(:) = map(ci,1);
    g(:) = map(ci,2);
    b(:) = map(ci,3);
    
    % New image
    res = zeros(il,iw,3);
    res(:,:,1) = r; 
    res(:,:,2) = g; 
    res(:,:,3) = b;

    版本1结果图。。。被嫌弃说。。颜色很奇怪。。于是调整了。。结果如图二。。。

  • 相关阅读:
    七类网线 支持10gb/s的速度的计算方法
    Linux 压缩 解压缩 命令相关
    [至顶网] Win2019 发布 LTSC 10年支持期
    安装报错信息 改天找人帮忙看下.
    [学习]仿照cnblog 搭建 Oracle RAC 双节点 困.. 后续做不下去了..
    Windows 作为 openssl server端时的处理
    阿里云构建Kafka单机集群环境
    nginx解决跨域
    让网站永久拥有HTTPS
    ORA-01940: cannot drop a user that is currently connected 问题解析
  • 原文地址:https://www.cnblogs.com/luckystar-67/p/3722281.html
Copyright © 2020-2023  润新知