本文主要是介绍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>Jcolormap_out= A(i,Eshort,:);
elsecolormap_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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!