梯度颜色标度与伽马参数? [英] gradient colour scale with gamma parameter?

查看:287
本文介绍了梯度颜色标度与伽马参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些成像数据具有非常微弱的对比度和相当多的噪音,当我用线性颜色标度显示它不能很好地显示。在像imageJ或photoshop的成像软件中,有一个色调曲线,可以调整以非线性方式撞击对比度,并有效地拉伸某些感兴趣区域的比例以查看更多细节。


$ b作为这种非线性调整参数的最简单的情况,@BrianDiggs指出 bias 参数 colorRamp ,其仍需要数据的先前转换为[0,1]。
我想将非线性标度推广到 x ^ gamma 以外的其他函数,因此下面的函数实际上不使用 c> c> c>

$

像我重塑的轮子;是否已经有这样的工具,用于连续的色标在R​​?

解决方案

这是一个可能的解决方案,

 code> set.seed(123)
x
库b
$ b curve_pal< - function(x,colors = rev(blues9),
fun = function(x)x ^ gamma,
n = 10,gamma = 1)
{
#function that maps [0,1] - >颜色
palfun< - colorRamp(colors = colors)

#现在将n个等间隔区域中的数据分割,线性映射到[0,1]
xcuts& - cut(x,breaks = seq(min(x),max(x),length = n))
xnum < - as.numeric(xcuts)

#需要工作围绕NA值,使得colorRamp / rgb choke
testNA < - is.na(xnum)
xsanitised < - ifelse(testNA,0,fun(rescale(xnum)))

在[0,1]中的非NA值被赋予它们的颜色
ifelse(testNA,NA,rgb(palan(xsanitised),maxColorValue = 255))
}
b $ b库(gridExtra)
grid.newpage()
grid.arrange(rasterGrob(curve_pal(x,gamma = 0.5),wid = 1,heig = 1,int = F),
rasterGrob(curve_pal(x,gamma = 1),wid = 1,heig = 1,int = F),
rasterGrob(curve_pal(x,gamma = 2),wid = 1,heig = 1,int = F),
nrow = 1)


I have some imaging data with very faint contrast and quite a bit of noise, and when I display it with a linear colour scale it doesn't show well. In imaging software such as imageJ or photoshop, there's a tonal curve that one can tune to bump the contrast in a nonlinear fashion and effectively stretch the scale on some region of interest to see more details.

As a simplest case of such nonlinear tuning parameter, @BrianDiggs pointed out the bias argument to colorRamp, which still requires previous tranformation of the data to be in [0, 1]. I'd like to generalise the non-linear scale to other functionals than x^gamma, therefore the function below doesn't actually use bias in colorRamp but does the transformation on the data side.

I feel like I'm reinventing the wheel; is there already such a tool for continuous colour scales in R?

解决方案

Here is a possible solution,

set.seed(123)
x <- sort(runif(1e4, min=-20 , max=120))

library(scales) # rescale function

curve_pal <- function (x, colours = rev(blues9), 
                       fun = function(x) x^gamma,
                       n=10, gamma=1) 
{
    # function that maps [0,1] -> colours
    palfun <- colorRamp(colors=colours)

    # now divide the data in n equi-spaced regions, mapped linearly to [0,1]
    xcuts <- cut(x, breaks=seq(min(x), max(x), length=n))
    xnum <- as.numeric(xcuts)

    # need to work around NA values that make colorRamp/rgb choke
    testNA <- is.na(xnum)
    xsanitised <- ifelse(testNA, 0, fun(rescale(xnum))) 

    # non-NA values in [0,1] get assigned their colour
    ifelse(testNA, NA, rgb(palfun(xsanitised), maxColorValue=255))
}

library(gridExtra)
grid.newpage()
grid.arrange(rasterGrob(curve_pal(x, gamma=0.5), wid=1, heig=1, int=F),
             rasterGrob(curve_pal(x, gamma=1), wid=1, heig=1, int=F), 
             rasterGrob(curve_pal(x, gamma=2), wid=1, heig=1, int=F), 
             nrow=1)

这篇关于梯度颜色标度与伽马参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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