R 带伽马参数的渐变色标?

R 带伽马参数的渐变色标?,r,graphics,colors,gradient,R,Graphics,Colors,Gradient,我有一些成像数据,对比度很弱,噪音很大,当我用线性色标显示时,显示不好。在像imageJ或photoshop这样的成像软件中,有一条色调曲线,人们可以对其进行调整,以非线性方式增强对比度,并有效地拉伸感兴趣区域的比例,以查看更多细节 作为这种非线性调谐参数的最简单例子,@BrianDiggs指出了colorRamp的偏差参数,它仍然要求数据的先前转换在[0,1]中。 我想将非线性尺度推广到除x^gamma之外的其他函数,因此下面的函数在colorRamp中实际上不使用bias,而是在数据端进行转

我有一些成像数据,对比度很弱,噪音很大,当我用线性色标显示时,显示不好。在像imageJ或photoshop这样的成像软件中,有一条色调曲线,人们可以对其进行调整,以非线性方式增强对比度,并有效地拉伸感兴趣区域的比例,以查看更多细节

作为这种非线性调谐参数的最简单例子,@BrianDiggs指出了
colorRamp
偏差
参数,它仍然要求数据的先前转换在[0,1]中。 我想将非线性尺度推广到除
x^gamma
之外的其他函数,因此下面的函数在
colorRamp
中实际上不使用
bias
,而是在数据端进行转换


我觉得我在重新发明轮子;在R中是否已经有这样一个用于连续色标的工具

这里有一个可能的解决方案

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)
set.seed(123)
x