16bit image separation

   5002   4   2
User Avatar
Member
212 posts
Joined: July 2005
Offline
So I have a 16bit grayscale image
and I need to extract the first 8bits and put that in the the R channel
and then put the next 8bits into the G channel
and then export an 8bit image of RGB where B is black.

That will allow me to keep detail but keep things as an 8bit image.

Need some pointers on this for Hcomposite? i don't want to do this in Photoshop.

thanks
-k
User Avatar
Member
1799 posts
Joined: Oct. 2010
Offline
would the idea be that you want 0 to 0.5 stored in red and 0.5 to 1.0 stored in green? if so, try this in COPs

- use a file COP to bring in your 16 bit image
- use a color COP to create a 8 bit image of the same res as the 16 bit image
- drop a VOP COP filter and feed in the first input your color COP, and in the second input your 16 bit image
- dive inside the VOP COP, and use a COP input VOP to import the second input image plane (the 16 bit one)
- compare the incoming pixel with a compare VOP and see if it is less than 0.5
- feed the result into a two way switch COP condition input
- feed the incoming pixel to a get vector component VOP to get the first element (since it is grayscale)
- feed the output of that into two different float to vectors: one that inputs into the red, the other one into the green
- out of each one of those, use a fit VOP to stretch the red from 0-0.5 to 0-1, and the green from 0.5-1 to 0-1
- feed the output vectors of those into the two way switch so tha tthe appropriate shuffle happens depending on the pixel value
- feed the output of the two way switch to he output of the VOP COP
-assuming I did not forget anything and understood your question, you should be done
- switch the image in the file COP to convert as many images as you want
-G
User Avatar
Member
4189 posts
Joined: June 2012
Offline
Are you are trying to fit 16bit, 65,536, values into 8bit, 256 values? Then you should use all available channels. ie. r,g,b,a - you could then get 256*4=1024. A 10bit integer file.
User Avatar
Member
8833 posts
Joined: July 2007
Offline
I think in theory you can split it bytewise into 2 8bit chunks (that would not make sense visually), but that would probably be easier in Python COP rather than VEX
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
72 posts
Joined: Sept. 2012
Offline
MartybNz
Then you should use all available channels. ie. r,g,b,a - you could then get 256*4=1024. A 10bit integer file.
Really? …that sounds like quite an interesting computing architecture

An rgba image with 8bits per channel can (ofcourse) store 4*8=32bits of data so packing 16bits into two of those channels is no problem.

Try this in an inline vex code vopcop node to pack and unpack to and from 0-1 range float values.

// pack
int int_R = int($R * 0xffff);
$R_out = float(int_R & 0xff) / 256.0; // low 8 bits
$G_out = float(shr(int_R,8)) / 256.0; // hi 8 bits
// unpack
int int_R = int($R * 256);
int int_G = int($G * 256);
$R_out = float( shl(int_G,8) | int_R ) / float(0xffff);

…and watch out for gamma/colorspace transformations when writing the data out…
  • Quick Links