dahtah / imager

R package for image processing
GNU Lesser General Public License v3.0
187 stars 43 forks source link

16-bit per channel images? #135

Closed mconsidine closed 4 years ago

mconsidine commented 4 years ago

I have a video that has 16-bit per channel frames (SER format, in my particular case, monochrome) and I am trying to write some R code using imageR to read the video and convert it to cimg frames.

But it looks like "as.cimg" only wants to create 8-bit per channel frames. Is that correct? More generally: can I work with 16-bit per channel images with imageR? I'm hoping I've overlooked passing some parameter.

TIA, mconsidine

dahtah commented 4 years ago

Thanks, this should be looked into, will get to it when I have time. In the meanwhile you can use cimg(readTIFF("example.tiff")/(2^16-1)) and maybe flip/mirror as needed. I believe 16 bits/channel is supported.

mconsidine commented 4 years ago

The hint about readTIFF got me headed in the direction of the solution, an example of which is posted in the attached text file. In short, I'm opening the file and reading it as binary data. readTIFF works for one image. The SER file is a video format. So there is a header block, frames of data and then a trailing block (possibly) of timestamps. So, I read the 178 byte header block, loop through reading frames and converting them to cimg and then finally read a block of timestamps. Also, there's a function to turn 8 bytes into a large number so that a timestamp can be read.

The attached works for me. But it is undoubtedly not all-encompassing and there are probably edge cases that could break it. Perhaps its helpful to someone else, though. mconsidine

readSER.txt