猜测地图上的rgb渐变?(guessing the rgb gradient from a map?)

编程入门 行业动态 更新时间:2024-10-21 09:35:34
猜测地图上的rgb渐变?(guessing the rgb gradient from a map?)

我有一张像这样的比例的地图:(数字只是一个例子)

其中描述了地图上的单个变量。 但是,我无法访问原始数据,并且对图像处理几乎一无所知。 我所做的是使用PIL来获取地图上每个点的像素坐标和RGB值。 只需使用pix = im.load()并为每个x,y保存pix[x,y] 。 现在我想用上面的梯度来猜测每个点的值。

这种梯度有标准公式吗? 受过训练的眼睛看起来很熟悉吗? 我已经访问了数学函数库以获取一些示例...但我不确定它是否使用色调,rgb高度函数或其他内容(为了使事情更容易,我还对某些绿色/眉毛/红色进行了颜色盲化):)

任何关于如何进行的技巧,图书馆,链接或想法,都将受到赞赏。 谢谢!

编辑:

根据回复和martineau的建议,我试图抓住顶部和底部的颜色:

def rgb2hls(colotup): '''converts 225 based RGB to 360 based HLS `input`: (222,98,32) tuple''' dec_rgb = [x/255.0 for x in colotup] # use decimal 0.0 - 1.0 notation for RGB hsl_col = colorsys.rgb_to_hls(dec_rgb[0], dec_rgb[1], dec_rgb[2]) # PIL uses hsl(360,x%,y%) notation and throws errors on float, so I use int return (int(hsl_col[0]*360), int(hsl_col[1]*100), int(hsl_col[2]*100)) def pil_hsl_string(hsltup): '''returns a string PIL can us as HSL color from a tuple (x,y,z) -> "hsl(x,y%,z%)"''' return 'hsl(%s,%s%%,%s%%)' % (hsltup[0], hsltup[1], hsltup[2]) BottomRed = (222,98,32) # taken with gimp TopBlue = (65, 24, 213) hue_red = pil_hsl_string(rgb2hls(BottomRed)) hue_blue = pil_hsl_string(rgb2hls(TopBlue))

然而它们出现了很大的不同......这让我担心使用rgb_to_hls函数来提取值。 或者我是在做一些非常错误的事情? 以下是使用代码转换为颜色的内容:

I have a map with a scale like this one: (the numbers are just an example)

which describes a single variable on a map. However, I don't have access to the original data and know pretty close to nothing about image processing. What I have done is use PIL to get the pixel-coordinates and RGB values of each point on the map. Simply using pix = im.load() and saving pix[x,y] for each x,y. Now I would like to guess the value of each point using the gradient above.

Is there a standard formula for such a gradient? Does it look very familiar to the trained eye? I have visited Digital Library of Mathematical Functions for some examples ... but I'm not sure if it's using the hue, the rgb height function or something else (to make things easier I'm also colorblind to some greens/brows/reds) :)

Any tips on how to proceed, libraries, links or ideas are appreciated. Thank you!

edit:

Following the replies and martineau's suggestion, I've tried to catch the colors at the top and bottom:

def rgb2hls(colotup): '''converts 225 based RGB to 360 based HLS `input`: (222,98,32) tuple''' dec_rgb = [x/255.0 for x in colotup] # use decimal 0.0 - 1.0 notation for RGB hsl_col = colorsys.rgb_to_hls(dec_rgb[0], dec_rgb[1], dec_rgb[2]) # PIL uses hsl(360,x%,y%) notation and throws errors on float, so I use int return (int(hsl_col[0]*360), int(hsl_col[1]*100), int(hsl_col[2]*100)) def pil_hsl_string(hsltup): '''returns a string PIL can us as HSL color from a tuple (x,y,z) -> "hsl(x,y%,z%)"''' return 'hsl(%s,%s%%,%s%%)' % (hsltup[0], hsltup[1], hsltup[2]) BottomRed = (222,98,32) # taken with gimp TopBlue = (65, 24, 213) hue_red = pil_hsl_string(rgb2hls(BottomRed)) hue_blue = pil_hsl_string(rgb2hls(TopBlue))

However they come out pretty different ... which makes me worry about using the rgb_to_hls function to extract the values. Or I'm I doing something very wrong? Here's what the color s convert to with the code:

最满意答案

有趣的问题..

如果你在HSL色彩空间中以250,85%,85% - > 21,85%,85%为单位进行顺时针走动,那么你的渐变非常接近你所展示的渐变。 明显的区别在于您的图像显示出相当窄的绿色值。

所以,如果你有4个幻数,那么你可以插入地图中的任何点。

这些当然是第一个也是最后一个颜色,也是第一个和最后一个比例值。 这是我在H通道上使用直线性渐变得到的图像(使用了gimp)。 在这里输入图像描述

编辑:我已经启动了一个程序来获取每一行的像素值,绘制结果图。 你可以看到,确实色相不是线性的,你还可以看到S&V通道在115左右(从图像顶部115像素)处确定下降。这确实对应于绿色带。

考虑到曲线的形状,我倾向于认为它们可能是为了模拟某些东西。 但是没有相关领域的经验来识别曲线的形状。

下面,我添加了HSV和RGB模型变化的图表。 图表的左侧代表条形图的顶部。 X轴标签代表像素

很有意思,我想。 书签。

在这里输入图像描述

在这里输入图像描述

Interesting question..

If you do a clock-wise walk in HSL color-space from 250,85%,85% --> 21,85%,85% you get a gradient very close to the one you've shown. The obvious difference being that your image exhibits a fairly narrow band of greenish values.

So, if you have the 4 magic numbers then you can interpolate to any point within the map.

These of course being the first and last colour, also the first and last scale value. Here's the image I got with a straight linear gradient on the H channel (used the gimp). enter image description here

EDIT: I've since whipped up a program to grab the pixel values for each row, graphing the results. You can see that indeed, the Hue isn't linear, you can also see the S & V channels taking a definite dip at around 115 (115 pixels from top of image) This indeed corresponds with the green band.

Given the shape of the curves, I'm inclined to think that perhaps they are intended to model something. But don't have the experience in related fields to recognise the shape of the curves.

Below, I've added the graphs for the change in both the HSV and RGB models. The left of the graph represents the top of the bar. The X-axis labels represent pixels

Quite interesting, me thinks. Bookmarked.

enter image description here

enter image description here

更多推荐

本文发布于:2023-08-04 12:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415974.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图上   rgb   guessing   gradient   map

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!