Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Raw image in R

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.

like image 503
Pierre-louis Stenger Avatar asked Oct 20 '25 12:10

Pierre-louis Stenger


1 Answers

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))
like image 75
Richard Faucheron Avatar answered Oct 23 '25 00:10

Richard Faucheron