Matlab提取colormap

文章目录

    • 简介
    • Matlab代码

简介

  • 使用Maltab依据截取的图片信息,提取colormap,供保存使用

Matlab代码

  • 提取函数
function colormap_out=Extract_Colormap(inputfig, colormapsize)% Creat a colormap array from the input figure.
% The figure is a colormap which you like very
% you can use the colormap_out in such a way: colormap(out)% 
% when you plot your own figures...xist(inputfig,'file')
if ~exist(inputfig,'file') 
   warning('You should provide a valid colormap figure!');
   return; 
end
colormap_out = zeros(colormapsize,3); 
A= imread(inputfig);
[I,J,K]= size(A);
Elong = max(I,J);
Eshort = int8(min(I,J)/2); 
i = linspace(3,Elong -2,colormapsize); 
i = int16(i);
if I>J
    colormap_out= A(i,Eshort,:); 
else
    colormap_out= A(Eshort,i,:); 
end  
colormap_out = squeeze(flipud(colormap_out));
colormap_out = double(colormap_out)/255;
end
  • 提取示例
clear;clc
colormapsize=200;
inputfig = 'example.png'; 
colormap_out=Extract_Colormap(inputfig, colormapsize); 

在这里插入图片描述

Matlab提取colormap_第1张图片

你可能感兴趣的:(Matlab相关,matlab,数据库,javascript)