20060210-All about pixel colors: Scaled indexed images

本文通过对比MATLAB中的image和imagesc函数,详细解释了如何显示图像,并探讨了CDataMapping属性的不同设置对图像颜色的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文:http://blogs.mathworks.com/steve/2006/02/10/all-about-pixel-colors-part-3/

the relevant MATLAB image display function is imagesc.

Suppose, for example, we use a small magic square:

A = magic(5)

Now let's display A using image and a 256-color grayscale colormap:

map = gray(256);
image(A)
colormap(map)
title('Displayed using image')
The displayed image is very dark. That's because the element values of A vary between 1 and 25, so only the first 25 entries of the colormap are being used. All these values are dark.

Compare that with using imagesc:

imagesc(A)
colormap(map)
title('Displayed using imagesc')
You can switch colormaps on the fly, and the values of A will be mapped onto the new colormap.

colormap(jet)
title('Scaled image using jet colormap')
Let's dig into the low-level Handle Graphics properties that are controlling these behaviors. Image objects have a property called CDataMapping.

close all
h = image(A);
get(h, 'CDataMapping')
close

ans =

direct
You can see that its default value is 'direct'. This means that values of A are used directly as indices into the colormap. Compare that with using imagesc:

h = imagesc(A);
get(h, 'CDataMapping')
close

ans =

scaled
The imagesc function creates an image whose CDataMapping property is 'scaled'. Values of A are scaled to form indices into the colormap. The specific formula is:


C is a value in A, and  and  come from the CLim property of the axes object.

h = imagesc(A);
get(gca, 'CLim')
close
It's not a coincidence that the CLim (color limits) vector contains the minimum and maximum values of A. The imagesc function does that by default. But you can also specify your own color limits using an optional second argument to imagesc:

imagesc(A, [10 15])
colormap(gray)
title('imagesc(A, [10 15])')

经度 纬度 高程 日期 时间 PWV(mm) 温度(℃) 湿度(%) 气压(hPa) 水汽压 湿折射率 小时降雨量(mm) 116.5279384 39.85244748 87.489 2024-08-12 1:00:00 49.764431 30.38 61.04 99130 26.4958 114.25 0 116.5279384 39.85244748 87.489 2024-08-12 2:00:00 49.736067 31.44 59.42 99170 27.3986 117.343 0 116.5279384 39.85244748 87.489 2024-08-12 3:00:00 49.671329 30.09 63.14 99180 26.9559 116.451 0 116.5279384 39.85244748 87.489 2024-08-12 4:00:00 49.798781 31.01 61.52 99200 27.6819 118.883 0 116.5279384 39.85244748 87.489 2024-08-12 5:00:00 49.427338 31.46 60.09 99180 27.739 118.786 0 116.5279384 39.85244748 87.489 2024-08-12 6:00:00 48.944255 31.76 57.78 99190 27.1302 115.955 0 116.5279384 39.85244748 87.489 2024-08-12 7:00:00 48.210558 31.25 62.23 99200 28.3863 121.721 0 116.5279384 39.85244748 87.489 2024-08-12 8:00:00 48.531075 32.07 55.1 99250 26.3294 112.31 0 116.5279384 39.85244748 87.489 2024-08-12 9:00:00 47.353073 30.69 61.02 99310 26.9605 116.023 0 116.5279384 39.85244748 87.489 2024-08-12 10:00:00 47.838974 29.41 67.7 99370 27.7947 120.602 0 116.5279384 39.85244748 87.489 2024-08-12 11:00:00 49.338809 27.66 76.25 99460 28.283 124.117 0 116.5279384 39.85244748 87.489 2024-08-12 12:00:00 49.590511 26.83 80.49 99580 28.4389 125.476 0 116.5279384 39.85244748 87.489 2024-08-12 13:00:00 49.533455 26.76 79.78 99660 28.0723 123.915 0 116.5279384 39.85244748 87.489 2024-08-12 14:00:00 49.957019 26.55 78.5 99700 27.2827 120.594 0 116.5279384 39.85244748 87.489 2024-08-12 15:00:00 48.53558 26.26 81.83 99720 27.958 123.813 0 116.5279384 39.85244748 87.489 2024-08-12 16:00:00 48.69868 25.86 80.96 99760 27.0144 119.947 0 116.5279384 39.85244748 87.489 2024-08-12 17:00:00 50.5339 25.04 89.55 99760 28.4606 127.047 0 116.5279384 39.85244748 87.489 2024-08-12 18:00:00 49.518931 24.76 89.87 99810 28.0894 125.62 0 现在有一个csv文件,文件组织格式如上,第一列是经度,第二列是维度,后面是该点上的一些属性值,往下行读取全部数据,当经纬度跟上面不一样的时候,便是第二个点了,现在要将csv文件读取到python中data_scaled中里面,data_scaled的组织格式是,如果是三个点的话,就是第一列是第一个点的维度、第二列是第二个点的维度、第三列是第三个点的维度、第四列是第一个点的经度、第五列是第二个点的经度、第六列是第 三个点的经度、第7到第11列是第一个点的属性值、第8到第11列是第二点的属性值,第12到第15列是第三个点的属性值。每一行代表不同时间点。现在要将csv表中的PWV(mm) 温度(℃) 湿度(%) 气压(hPa) 水汽压 湿折射率 小时降雨量(mm)作为每个点属性值,现在编写python导出data_scaled文件
最新发布
03-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值