I'm looking for a way to import Raw image into R.
Indeed, there are many packages which permit to import .bmp, .png, .jpeg or .tiff images into R (ImageMagick, EBImage, imager, bmp, tiff, TIFF, pixmap, Momocs and many others..) but these files formats have a conversion (white balance, contrast, saturation..) and the pictures can be different (in term of saturation, lightness..) even if the taking pictures is standardised but the objects have different size or colour. The Raw picture haven't this problem.
I know the extension differ according to the brand of the camera, which complicates the thing.
But i would like to analyse the difference between saturation, lightness in a more precise and relevant way than .jpeg or .tiff.
Despite my research, I block on the first step : The Raw image importation..
Has someone already achieved this pass ?
Does it exist bash command to import this kind of file ?
I'm not looking to see the picture, but to have access of the raw data.
You can use the readRaw() function from the hexView package :
library(hexView)
raw_image <- readRaw("image_path")
The data is then in raw_image$fileRaw. It is stored as a vector of class "raw".
You can simply turn it into a matrix :
image_matrix <- matrix(raw_image$fileRaw, nrow = image_height, ncol = image_width, byrow = TRUE)
It should recreate what you had in your raw file.
NB : image_height and image_width would be in pixels.
Now you can easily plot your image via as.raster:
plot(as.raster(image_matrix))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With