Deals with image value superior to 0,1 range
2
0
Entering edit mode
@valerianmeline-12890
Last seen 7.7 years ago

Hello, 

I use EBImage to analyse chlorophyll fluorescence images. The pixels values are contains between 0 and 1500. I can read these images but I can't write them while keeping the fluorescence values.

I can't export them with the intensity contrast  (0,1 range) because I need to keep these chlorophylll fluorescence range values.

Do you know how can i write these images without rescaling between 0 and 1 ?

Cheers, 
Valérian

value ebimage writeImage error • 1.3k views
ADD COMMENT
2
Entering edit mode
Andrzej Oleś ▴ 750
@andrzej-oles-5540
Last seen 4.1 years ago
Heidelberg, Germany

Dear Valérian,

you can save your images as 16 bit TIFFs and transform between the integer and double pixel representation on read/write. For this when saving your images you would divide the pixel values by the maximum value which can be stored as unsigned integer (UINT16), which is 2^16-1.  To transform the data back to integer range after loading the image multiply it by  2^16-1. The resulting image will contain integer values but stored internally as doubles, so in order to obtain output identical to your original data you want to change the storage mode back to "integer".  For convenient use it's probably a good idea to define some wrapper functions, say writeImageInt and readImageInt.

library(EBImage)

max16b = 2^16-1

# test image containing integer values
x = Image(1:max16b, c(2^8, 2^8))

f = "tmp.tiff"

# scale to double 0:1 range on write
writeImageInt = function(x, ...) {
  writeImage(x/max16b, ...)
}

# rescale to integers on read
readImageInt = function(...) {
  y = readImage(...) * max16b
  storage.mode(y) = "integer"
  y
}

identical(x, readImageInt(writeImageInt(x, f)))
## [1] TRUE
ADD COMMENT
0
Entering edit mode
@valerianmeline-12890
Last seen 7.7 years ago

Hello Andrzej,

Perfect it works for my data, Thank you very much for you fast answer

Valérian

ADD COMMENT

Login before adding your answer.

Traffic: 446 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6