英文:
Reproduce color palette from an image containing that color palette (IVIS machine)
问题
I would like to know if that is possible to reproduce a color palette from an image.
Here is an example. Pages 1 and 3 show a rainbow palette in the figure legend.
The software is proprietary and has very little room for customization. I would like to regenerate the legend by R (or any other programming language, e.g. python) but retain the scale/ range of the colors.
I recognize that some color picker tools are available. However, the resolution of the palette is quite low, and often 3-4 colors are displayed in the same row. I am not sure which color I should pick in the raster image.
英文:
I would like to know if that is possible to reproduce a color palette from an image.
Here is an example. Pages 1 and 3 show a rainbow palette in the figure legend.
The software is proprietary and has very little room for customization. I would like to regenerate the legend by R (or any other programming language, e.g. python) but retain the scale/ range of the colors.
I recognize that some color picker tools are available. However, the resolution of the palette is quite low, and often 3-4 colors are displayed in the same row. I am not sure which color I should pick in the raster image.
答案1
得分: 1
Base R
有一个rainbow
调色板,类似于链接的PDF中所示。
一个更好的选择可能是viridis
package中的turbo
颜色映射,它在可见光谱中更渐变过渡。
这个PDF是关于R中颜色的一个很好的通用参考,可能会帮助您构建您想要复制的渐变。
在ggplot2
中,您可以使用scale_gradient
(link) 来创建这些调色板。
library(ggplot2)
library(scales)
ggplot(mtcars, aes(factor(cyl), disp, fill = mpg)) +
geom_col() +
scale_fill_gradientn(colors = c(muted('red'), 'red', 'yellow1'))
<!-- -->
<sup>于2023-04-19创建,使用 reprex v2.0.2</sup>
英文:
Base R
has a rainbow
palette, which is similar to what is shown in the linked PDF
A better option might be the turbo
color map in the viridis
package, which transitions more gradually across the visible spectrum.
This PDF is a great general reference to colors in R, and may help you construct the gradient you're aiming to replicate.
In ggplot2
, you can create these sorts of palettes using scale_gradient
(link).
library(ggplot2)
library(scales)
ggplot(mtcars, aes(factor(cyl), disp, fill = mpg)) +
geom_col() +
scale_fill_gradientn(colors = c(muted('red'), 'red', 'yellow1'))
<!-- -->
<sup>Created on 2023-04-19 with reprex v2.0.2</sup>
答案2
得分: 0
你可以使用OpenCV(cv2)库并将颜色数据导出为直方图。还可以在图像的特定区域应用掩码,以提取该部分的颜色数据。
示例/文档可在这里找到:Histograms - 1 : Find, Plot, Analyze,还有一个可能更适合您的示例,展示如何创建2D直方图:Histograms - 3 : 2D Histograms
希望对您有帮助!
英文:
You can use OpenCV (cv2) library and export the color data as a histogram. It's also possible to apply a mask to a certain area of the image to extract the color data from that part.
For examples/documentation you can find more here: Histograms - 1 : Find, Plot, Analyze and this one might suite you a bit more where it shows how to create 2D histograms: Histograms - 3 : 2D Histograms
Hope this helps!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论