简体   繁体   中英

Does anybody know how to plot a graph in R with RGB values of a core sediment image?

I have an image of a core sediment and what I want to do is to make a simple plot in R with the RGB values separately, but at the same graph. Is there any advice about that? I attach th image file of the core. core sediment

Here's one option using the png package:

library(png)

img <- readPNG(readBin("https://i.stack.imgur.com/IvWI9.png", "raw", 1e6))
par(mfrow = c(1, 3))

lapply(1:3, function(i) {
  image(t(img[,,i]), col = grey(seq(0, 1, length = 256)), 
        main = c("Red", "Green", "Blue")[i], axes = FALSE)
})

The benefit here is that each of the three channels is held as a matrix in the the first three layers of the img array, so you can get the matrix of red values by doing:

red <- img[,,1]

and doing the same for green (2) and blue (3)

Created on 2020-11-28 by the reprex package (v0.3.0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM