在R中使用image()或rasterImage()叠加红/绿图像 [英] Superimpose red/green images in R using image() or rasterImage()

查看:367
本文介绍了在R中使用image()或rasterImage()叠加红/绿图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了突出显示两个相同大小的矩阵之间的差异,我希望以半透明的方式显示两个矩阵,其中一个矩阵使用红色阴影,另一个矩阵使用绿色阴影(在相同的地方产生黄色) 。



只显示一个矩阵我有

  library(grDevices )
matr = replicate(10,rnorm(20,mean = 0.5,sd = 0.1))
colpalette = colorRampPalette(c(black,red))
image ^ 0.2,col = colpalette(1000),useRaster = T)

有没有人知道如何我应该调整它以显示两个矩阵 matr1 matr2 叠加在红色/绿色中?



另外,对亮度和放大率有一点控制的最好方法是什么?结果图像的对比度?有没有比我现在使用的力量转换更好的方法?

干杯,
Tom


$ $ $ $ $ $ $ b $ matr1 = replicate(10,rnorm(20,mean = 0.5,sd = 0.1))
matr2 = replicate(10,rnorm(20,mean = 0.5,sd = 0.1))
matrdiff = log2(matr1 / matr2)
nbcolors = 1000
colpalette = colorRampPalette(c(red,yellow,green))(nbcolors)
breaks = c(seq(min(matrdiff),0,length.out = nbcolors / 2) ,0,
seq(0,max(matrdiff),length.out = nbcolors / 2))
image(matrdiff,col = colpalette,breaks = breaks,useRaster = T)


To highlight the difference between two identically sized matrices I would like to show the two superimposed in a semitransparent way using shades of red for the one matrix and shades of green for the other one (yielding yellow where they are identical) in R.

To display just one matrix I have

library(grDevices)
matr=replicate(10, rnorm(20,mean=0.5,sd=0.1))    
colpalette=colorRampPalette(c("black", "red")) 
image(matr^0.2,col = colpalette(1000),useRaster=T)

Does any one have any idea how I should adapt this to show two matrices matr1 and matr2 superimposed in red/green?

Also, what would be the best way to have a bit of control over the brightness & contrast of the resulting image? Are there better ways than the power transform I am using now?

cheers, Tom

解决方案

Ha just found an easy solution by first calculating the log2(difference) between the two matrices and plotting that using a palette with a break at zero. That makes sense, right?

library(grDevices)
matr1=replicate(10, rnorm(20,mean=0.5,sd=0.1)) 
matr2=replicate(10, rnorm(20,mean=0.5,sd=0.1))
matrdiff=log2(matr1/matr2)
nbcolors=1000
colpalette=colorRampPalette(c("red","yellow","green"))(nbcolors)
breaks = c(seq(min(matrdiff), 0, length.out=nbcolors/2), 0, 
           seq(0,max(matrdiff), length.out=nbcolors/2))
image(matrdiff,col=colpalette,breaks=breaks,useRaster=T)

这篇关于在R中使用image()或rasterImage()叠加红/绿图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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