如何填写图像上的红色矩形与白色背景

时间:2017-09-26 21:50:28

标签: r image plot polygon

尝试使用白色背景在图像上绘制一个红色矩形而不掩盖字母。请参阅下面的图1.如何使其像图2一样?我试过alpha,它看起来像图3,它没有图2那么暗。有什么建议吗?我正在研究R.

感谢。

 img <- readPNG("test.png")
      width<-dim(img)[2]
      height<-dim(img)[1]

  imgNamePlot<-paste("testPlot","png",sep='_EE.')
  png(imgNamePlot, width = width, height = height, res=300)
  op=par(mar = c(0, 0, 0, 0))
  plot(c(0, width), c(0, height), type = "n", xlab = "", ylab = "",xaxs = "i",yaxs = "i")
  rasterImage(img, 0, 0, width, height, interpolate = F)

  image <- as.raster(rgb(255, 0,  0, 255, maxColorValue = 255))
  geneWidth<-46
  geneHeight<-17
  geneX<-188
  geneY<-519
  rasterImage(image, geneX-0.5*geneWidth+1, height-geneY-0.5*geneHeight-1,               geneX-0.5*geneWidth+geneWidth+1, height-geneY-0.5*geneHeight+geneHeight-1,              interpolate=FALSE)  

  dev.off()

Figure 1:My plot

Figure 2:How can I plot red rectange without mask the font?

Figure 3: plot with alpha

0 个答案:

没有答案