Login  Register

Re: Using setColor(r,g,b) to pseudocolor Bayer Raw Image

Posted by Daddymoen on Dec 20, 2012; 3:42pm
URL: http://imagej.273.s1.nabble.com/Using-setColor-r-g-b-to-pseudocolor-Bayer-Raw-Image-tp5001221p5001232.html

Michael,

I saw your post in my forum searches and tried it but I didn't understand what I was looking at when I viewed the resulting images.

To make sure I understand correctly the first result of your macro should be 4, half-size images:
 
One image with all R pixels and no Gs or Bs;
One with all G1 pixels and no Rs, G2s or Bs
One with all G2 pixels, no Rs, G1s nor Bs
One with all B pixels , no Rs, G1s nor G2s

These images will each have the original, unaltered R, G1, G2, B pixel intensity values of my original Bayer Raw image?  Then, when these 4 new images are staked (recombined or superimposed over each other) that result will be a sort of "flattened" 16-bit per channel stack in which each pixel location in the new, half-size image will have those original, unaltered R,G1,G2,B values?

So, if I looked at the pattern of pixels in the first four rows and columns at the upper left corner of the image (the 0,0 location) before running your macro they would look like this in the original, full size image:

         |  Col 0 |  Col 1  | Col 2  | Col 3  |
Row 0    R        G1          R         G1
Row 1    G2       B          G2         B
Row 2    R        G1          R         G1    
Row 3    G2       B          G2         B  

After running your macro, stacking and "flattening" (without blending the 2 G channels) they should look like this in the half size image:

          |     Col 0       |       Col 2      |
Row 0    R        G1          R         G1
            G2       B          G2         B

Row 1    R        G1          R         G1    
            G2       B          G2         B  

I would like to retain both of the original G channels so as not to lose their data in my next analysis step, which is to run an algorithm to pseudocolor the image.  I am looking for patterns within very small pixel intensity variations for my digital phantom leaf photography project.  I found that pseudocoloring could  make these kinds of patterns somewhat visible in earlier, crude attempts back in my FilterMeister/PhotoShop days.  But the version of PhotoShop I have can't handle real 16-bit images, I can't find a way that it can even open my 16-bit Bayer Raw images.

So, I will need to find a way to use a 4-channel version of the "setColor" macro command to pseudocolor the final image.   Something that behaves like setColor(r,g,g,b)  

Thanks Michael, I'll start working with this and see what happens.

Daddymoen


Michael Schmid-3 wrote
Hi Dadymoen,

you could try the de-Bayer macro from my previous post (7-Aug-2012):

id = getImageID();
makeColorChannel("R", 0, -1);
selectImage(id);
makeColorChannel("G1", 0, 0);
selectImage(id);
makeColorChannel("G2", -1, -1);
selectImage(id);
makeColorChannel("B", -1, 0);

function makeColorChannel(name, dx, dy) {
  slices = nSlices();
  newWidth = getWidth()/2;
  newHeight = getHeight()/2;
  run("Duplicate...", "title=&name duplicate range=1-&slices");
  run("Translate...", "x=&dx y=&dy interpolation=None stack");
  run("Size...", "width=&newWidth height=&newHeight depth=&slices interpolation=None");
}

It will give you 4 channels. If you are satisfied with the small image size (1/2 of the original in x and y), use the Image Calculator to blend the two G(reen) channels, and then combine everything into a Stack (ImageJ has not 'real' RGB image with more than 8 bits per channel): Image>Stacks>Images to Stacks, then Image>Hyperstacks>Stack to Hyperstack, with 3 channels and 'Display Mode'='Composite'.
The result will look like an RGB image, but it's actually three 16-bit images. You can get a 24-bit RGB image (8 bits per channel) via Image>Type>RGB Color.

If you want to recover the original size, the makeColorChannel function could be easily extended to do a 'Size' back to the old size (but with interpolation), and than the translation back, again with interpolation of your choice (bilinear or bicubic). Again, combine to a Stack and create a 'Composite' Hyperstack from it.

Michael
________________________________________________________________
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Imagination is more important than knowledge.  Albert Einstein