Hello,
This is my first time using the imagej discussion board and I have a question about splitting raw bayer images: I have images that contain raw pixel grey values taken with a sensor that has a bayer color filter array. Attached is a cropped area of one of my images showing the raw RGB filtered pixels with no CFA interpolation (labeled *IMAGE 1*). What I want to do is separate these bayer images, resulting in four, half-sized color plane images that contain only the red, green, or blue pixels (see attached image below labeled *IMAGE 2*). I was wondering if there is any way to do this in imagej? -Aaron. |
On Sep 18, 2011, at 3:17 PM, Aaron Hendrickson wrote:
> Hello, > This is my first time using the imagej discussion board and I have a > question about splitting raw bayer images: > > I have images that contain raw pixel grey values taken with a sensor that > has a bayer color filter array. Attached is a cropped area of one of my > images showing the raw RGB filtered pixels with no CFA interpolation > (labeled *IMAGE 1*). What I want to do is separate these bayer images, > resulting in four, half-sized color plane images that contain only the red, > green, or blue pixels (see attached image below labeled *IMAGE 2*). I was > wondering if there is any way to do this in imagej? Here is a JavaScript script that splits a Bayer image into half-sized R, G1, G2 and B planes. -wayne imp = IJ.getImage(); ip = imp.getProcessor(); split(ip, "R", 0, 1); split(ip, "G1", 0, 0); split(ip, "G2", 1, 1); split(ip, "B", 1, 0); function split(ip, name, xstart, ystart) { var w = ip.getWidth(); var h = ip.getHeight(); var imp2 = IJ.createImage(name,"16-bit black",w/2,h/2,1); var ip2 = imp2.getProcessor(); var i = 0; for (var y=ystart; y<h; y+=2) { for (var x=xstart; x<w; x+=2) ip2.set(i++, ip.get(x,y)); } ip2.resetMinAndMax(); imp2.show(); } |
Hello,
Thank you for the script to split the images in 4. Actually I modified the script so that I get just the G2 plane as output. However, I need to perform this operation on an entire stack and I need to save the output as another stack. Can you please help me with that? Thanks a lot, Cheers, VKS |
VKS,
I am in need of a script that can do the same. However, what is different in my application is that I need to take my stack of Bayer images and split them into the four components (G1, R, G2, B) and save each channel of the split Bayer image. As a result I would end up with four stacks (one R channel stack, one G1 channel stack, one G2 channel stack, and one B channel stack). If anyone on the list can write a plugin that can do this I would be very greatful (it would save me a huge amount of time and probably some of the hair still on my head!). -Aaron. On Tue, Aug 7, 2012 at 5:41 AM, SVK <[hidden email]> wrote: > Hello, > > Thank you for the script to split the images in 4. Actually I modified the > script so that I get just the G2 plane as output. > However, I need to perform this operation on an entire stack and I need to > save the output as another stack. Can you please help me with that? > > Thanks a lot, > > Cheers, > VKS > > > > -- > View this message in context: > http://imagej.1557.n6.nabble.com/Splitting-raw-bayer-image-into-four-separate-color-plane-images-R-G1-G2-B-fixed-attached-images-tp3683144p4999662.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by SVK
Hi everyone,
here is a 'de-Bayer' script in ImageJ Macro language. It should work with single images and stacks. 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"); } (Note: The three 'run' commands at the end should be one long line each; join lines if the mailer splits them) Please check whether the channels are the correct ones; I have no sample image to try. The 'dx', 'dy' variables are actually the negative shifts; because it is the amount that the image has to be shifted to get the respective pixel to an even x & y position. If you want to, use the Image Calculator to create an average of the G1 and G2 channels. For better registry of the color channels, you may also want to translate the output by a suitable sub-pixel amount; with linear or bicubic interpolation (whatever you prefer). Michael ________________________________________________________________ On Aug 7, 2012, at 11:41, SVK wrote: > Hello, > > Thank you for the script to split the images in 4. Actually I modified the > script so that I get just the G2 plane as output. > However, I need to perform this operation on an entire stack and I need to > save the output as another stack. Can you please help me with that? > > Thanks a lot, > > Cheers, > VKS > > > > -- > View this message in context: http://imagej.1557.n6.nabble.com/Splitting-raw-bayer-image-into-four-separate-color-plane-images-R-G1-G2-B-fixed-attached-images-tp3683144p4999662.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Michael,
The macro you made works beautifully! Thank you for writing that....this is going to save me a huge amount of time. Thanks again, Aaron. On Tue, Aug 7, 2012 at 1:21 PM, Michael Schmid <[hidden email]>wrote: > Hi everyone, > > here is a 'de-Bayer' script in ImageJ Macro language. > It should work with single images and stacks. > > > 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"); > } > > (Note: The three 'run' commands at the end should be one long line each; > join lines if the mailer splits them) > > Please check whether the channels are the correct ones; I have no sample > image to try. > The 'dx', 'dy' variables are actually the negative shifts; because it is > the amount that the image has to be shifted to get the respective pixel to > an even x & y position. > > If you want to, use the Image Calculator to create an average of the G1 > and G2 channels. > For better registry of the color channels, you may also want to translate > the output by a suitable sub-pixel amount; with linear or bicubic > interpolation (whatever you prefer). > > Michael > ________________________________________________________________ > On Aug 7, 2012, at 11:41, SVK wrote: > > > Hello, > > > > Thank you for the script to split the images in 4. Actually I modified > the > > script so that I get just the G2 plane as output. > > However, I need to perform this operation on an entire stack and I need > to > > save the output as another stack. Can you please help me with that? > > > > Thanks a lot, > > > > Cheers, > > VKS > > > > > > > > -- > > View this message in context: > http://imagej.1557.n6.nabble.com/Splitting-raw-bayer-image-into-four-separate-color-plane-images-R-G1-G2-B-fixed-attached-images-tp3683144p4999662.html > > Sent from the ImageJ mailing list archive at Nabble.com. > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Michael Schmid
Michael,
WOW, the debayer code is impeccable!! ![]() As Aaron posted, that would save me huuugge amount of time. Thanks a lot! Srikanth. |
Hi,
I'm interested in learning how to convert bayer image to RGB using ImageJ. Can any one please provide the bayer raw image and the steps for converting to RGB Thanks, Sathya |
Free forum by Nabble | Edit this page |