如何从矩阵生成图像(带有浮点项) [英] How do I generate an image from a matrix (with floating point entries)

查看:88
本文介绍了如何从矩阵生成图像(带有浮点项)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个10 x 10的矩阵(数据按名称).我正在尝试生成图像:

I have a 10 by 10 matrix (data by name). I are trying to generate an image:

figure; 
(data);
colormap(gray);

保存的图像为560 * 420.如何生成10 x 10的图像?

The saved image is 560*420. How can I generate a 10 by 10 image?

我也想知道它是如何工作的.它是否首先将矩阵的-ve项设置为0,将项> 1设置为1,然后将所有项乘以255(如imwrite())?

Also I want to know how it works. Does it first set the -ve entries of the matrix to 0, entries >1 to 1 and then multiply all the entries by 255 (like imwrite())?

MATLAB中是否还有其他函数可以直接从浮点值转换(而无需将其转换为RGB,0 <= value <= 1)以生成图像?

Is there any other function in MATLAB to directly convert from floating values (without converting it to RGB, 0<=value<=1) to generate an image?

推荐答案

我确定以前已经有人问过这个问题,但是我找不到重复的问题.您使用 imagesc 函数将矩阵显示为图像.因此,您的上述代码应显示为:

I'm sure this has been asked before, but I can't find the duplicate. You use the imagesc function to display a matrix as an image. So your above code should read:

figure; 
imagesc(data);
colormap(gray);

颜色缩放由 caxis 控制,参数为caxis([cmin, cmax]).从文档中:

The color scaling is controlled by caxis, which takes arguments as caxis([cmin, cmax]). From the docs:

caxis([cmin cmax])将颜色限制设置为指定的最小值和最大值.小于cmin或大于cmax的数据值分别映射到cmincmax. cmincmax之间的值线性映射到当前的颜色图.

caxis([cmin cmax]) sets the color limits to specified minimum and maximum values. Data values less than cmin or greater than cmax map to cmin and cmax, respectively. Values between cmin and cmax linearly map to the current colormap.

因此,在这种情况下,最小值(如果您未设置caxis)将被映射为灰色颜色图中的最低颜色(白色),而最大值将被设置为黑色.要了解在设置灰度色图时使用了哪些RGB值,请将其分配给变量并查看其值(或将其绘制).

So in this case, the lowest value (if you haven't set a caxis) will be mapped to the lowest color in the gray colormap (white) and the highest value will be set to black. To see what values of RGB are used in setting the grayscale colormap, assign it to a variable and take a look at the values (or plot it).

gray=colormap('gray');

此外,请通读 colormap 上的文档

Also, read through the documentation on colormap

这篇关于如何从矩阵生成图像(带有浮点项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆