簡體   English   中英

帶有伽瑪參數的漸變色標?

[英]gradient colour scale with gamma parameter?

我有一些成像數據,對比度非常微弱,並且有很多噪點,當我以線性色標顯示它時,顯示效果不佳。 在諸如imageJ或photoshop之類的成像軟件中,存在一個色調曲線,可以調整該色調曲線以非線性方式增加對比度,並在某些感興趣區域上有效地縮放比例以查看更多細節。

由於這種非線性調諧參數的簡單的情況下,@BrianDiggs指出bias參數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)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM