Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
To All,
I'm just learning ImageJ macro writing and this problem has me stumped. I've searched the forum posts looking for clues. Hopefully a more experienced macro writer can point me in the right direction to find a solution. Using DCRaw (-v -4 -D -T filename.crw) I've converted a Camera Raw file to a 16-bit Tiff, Bayer Raw file. The resulting image file is not demosaiced or interpolated so the pixel intensity data is as close to the original camera sensor values as I know how to get. The 16-bit image has values in the range of 0 to 1023 (camera's 10-bit sensor range) with one value per pixel in an RGGB (2x2) pattern. I want to pseudocolor this image using a method that writes RGB values to each pixel location. The LUTs available have more than one pixel intensity value in each bin which is too coarse for my application. (In the past I've used an algorithm in a FilterMeister filter that worked well. But alas, FilterMeister is C+, ImageJ is Java, and me no speakee Java.) As an experiment a wrote a macro to see if I could pseudocolor the Bayer Raw image at all. I attempted to change all the pixels in the image to Red using the following code. // My first program to Color Bayer Raw Pixels print("This Macro Colors Bayer Raw Pixels"); // Color all pixels Red for (j=0; j < getHeight();j+=1) { for (i = 1; i < getWidth(); i+=1) { setColor(255,0,0); } } updateDisplay(); print("I'm Done"); Needless to say if that code had worked I wouldn't be here asking for assistance. I assume there is something about my Bayer Raw image, my macro, or my lack of knowledge that won't allow my novice's approach to work. Is there a way to do this? Is there another approach to pseudocoloring 16-bit Bayer Raw images that might succeed? Open to suggestions, Daddymoen
Imagination is more important than knowledge. Albert Einstein
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
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 ________________________________________________________________ On Dec 19, 2012, at 23:06, Daddymoen wrote: > To All, > > I'm just learning ImageJ macro writing and this problem has me stumped. > I've searched the forum posts looking for clues. Hopefully a more > experienced macro writer can point me in the right direction to find a > solution. > > Using DCRaw (-v -4 -D -T filename.crw) I've converted a Camera Raw file to a > 16-bit Tiff, Bayer Raw file. The resulting image file is not demosaiced or > interpolated so the pixel intensity data is as close to the original camera > sensor values as I know how to get. The 16-bit image has values in the > range of 0 to 1023 (camera's 10-bit sensor range) with one value per pixel > in an RGGB (2x2) pattern. > > I want to pseudocolor this image using a method that writes RGB values to > each pixel location. The LUTs available have more than one pixel intensity > value in each bin which is too coarse for my application. (In the past I've > used an algorithm in a FilterMeister filter that worked well. But alas, > FilterMeister is C+, ImageJ is Java, and me no speakee Java.) As an > experiment a wrote a macro to see if I could pseudocolor the Bayer Raw image > at all. I attempted to change all the pixels in the image to Red using the > following code. > > // My first program to Color Bayer Raw Pixels > print("This Macro Colors Bayer Raw Pixels"); > // Color all pixels Red > for (j=0; j < getHeight();j+=1) > { for (i = 1; i < getWidth(); i+=1) > { setColor(255,0,0); > } > } > updateDisplay(); > print("I'm Done"); > > Needless to say if that code had worked I wouldn't be here asking for > assistance. I assume there is something about my Bayer Raw image, my macro, > or my lack of knowledge that won't allow my novice's > approach to work. > > Is there a way to do this? Is there another approach to pseudocoloring > 16-bit Bayer Raw images that might succeed? > > Open to suggestions, > > Daddymoen > ... [show rest of quote] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by Daddymoen
I do not have a lot of experience with writing macros but here is a link to
a DeBayer plug-in that I have used to convert Bayer Image to RGB. Hope this helps. http://www.umanitoba.ca/faculties/science/astronomy/jwest/plugins.html -Aaron. On Wed, Dec 19, 2012 at 5:06 PM, Daddymoen <[hidden email]> wrote: > To All, > > I'm just learning ImageJ macro writing and this problem has me stumped. > I've searched the forum posts looking for clues. Hopefully a more > experienced macro writer can point me in the right direction to find a > solution. > > Using DCRaw (-v -4 -D -T filename.crw) I've converted a Camera Raw file to > a > 16-bit Tiff, Bayer Raw file. The resulting image file is not demosaiced or > interpolated so the pixel intensity data is as close to the original camera > sensor values as I know how to get. The 16-bit image has values in the > range of 0 to 1023 (camera's 10-bit sensor range) with one value per pixel > in an RGGB (2x2) pattern. > > I want to pseudocolor this image using a method that writes RGB values to > each pixel location. The LUTs available have more than one pixel intensity > value in each bin which is too coarse for my application. (In the past > I've > used an algorithm in a FilterMeister filter that worked well. But alas, > FilterMeister is C+, ImageJ is Java, and me no speakee Java.) As an > experiment a wrote a macro to see if I could pseudocolor the Bayer Raw > image > at all. I attempted to change all the pixels in the image to Red using the > following code. > > // My first program to Color Bayer Raw Pixels > print("This Macro Colors Bayer Raw Pixels"); > // Color all pixels Red > for (j=0; j < getHeight();j+=1) > { for (i = 1; i < getWidth(); i+=1) > { setColor(255,0,0); > } > } > updateDisplay(); > print("I'm Done"); > > Needless to say if that code had worked I wouldn't be here asking for > assistance. I assume there is something about my Bayer Raw image, my > macro, > or my lack of knowledge that won't allow my novice's > approach to work. > > Is there a way to do this? Is there another approach to pseudocoloring > 16-bit Bayer Raw images that might succeed? > > Open to suggestions, > > Daddymoen > > > > > > -- > View this message in context: > http://imagej.1557.n6.nabble.com/Using-setColor-r-g-b-to-pseudocolor-Bayer-Raw-Image-tp5001221.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > ... [show rest of quote] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by Michael Schmid
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
... [show rest of quote]
Imagination is more important than knowledge. Albert Einstein
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by Aaron Hendrickson
Aron,
Thanks, Ill check that out. Daddymoen
... [show rest of quote]
Imagination is more important than knowledge. Albert Einstein
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by Daddymoen
To All,
Been thinking about this some more and would like to run an idea past more experienced folks. I'm not familiar enough with ImageJ macros to know if this idea is possible. Feedback on this proposed, alternate method would be appreciated: 1. Create a new, "empty" 8-bit RGB image of exactly the same width and height (in pixels) as my Bayer Raw image and save it as some name, like maybe EmptyRGB.tiff or EmptyRGB.jpg 2 Run a macro in which I: 2a. Open my 16-bit, Bayer Raw image which has only a single pixel intensity value at each pixel location. 2b. Open my 8-bit, EmptyRGB.Tiff image which has three values per pixel, one r, one g and one b. 3. With both of these images simultaneously open. 4. Use a "for/next type" loop to read the single pixel value in the Bayer Raw image (to a variable) starting at location (0,0) 5. Use this variable in an algorithm (similar to a LUT) to select rgb values for a specific color (for example 255, 0, 0 for Red). (Note: I think I can handle this part) 6. Then somehow (setColor(r,g,b)?) insert these selected rgb values into the newly created, "empty" 8-bit RGB image at location (0,0) 7. Repeat this loop until all the pixel locations in the 16-bit Bayer Raw image have been used to psuedo-color all the corresponding locations in the 8-bit RGB image. 8. Then save the pseudo-colored 8-bit RGB image as something like, BayerColored.Tiff This approach sort of uses the Bayer Raw file as if it is an array of values, but it's actually just a 16-bit image file. It's probably a typical novice's, brute force approach that could be more elegantly done by a more experienced person, if it can work at all. Hopefully my description conveys the concept. I think I can easily create the "empty" 8-bit RGB file of the correct dimensions by just using DCRaw to convert a RAW file from the same camera into an ordinary, demosaiced and interpolated RGB file. As preparation I might even create a macro to change all the pixels in this empty file to black (0,0,0) or some other color by using setColor(r,g,b) so it doesn't contain any real image's data. So, is this approach possible? If so, any clues about how actually do it? The part I am not sure about is how to have both images simultaneously open and then go back and forth between reading the Bayer Raw image pixel, selecting the rgb values with my algorithm, and writing the algorithm result to the RGB image. I look forward to comments and suggestions. Daddymoen
Imagination is more important than knowledge. Albert Einstein
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
> The part I am not sure about is how to have both images simultaneously open
> and then go back and forth between reading the Bayer Raw image pixel, > selecting the rgb values with my algorithm, and writing the algorithm result > to the RGB image. So you want to loop over the pixels of the source and destination image using getPixel and setPixel? I believe you would need to call selectImage or selectWindow to swap the image context back and forth: 'selectImage(id) Activates the image with the specified ID (a negative number). If id is greater than zero, activates the idth image listed in the Window menu. The id can also be an image title (a string). selectWindow("name") Activates the window with the title "name".' The problem with this technique that swapping the selected image back & forth for every pixel would be extremely flickery and slow. The getPixel and setPixel methods work very well for in-place image conversions. Perhaps real IJ macro experts know of a more subtle way to swap the image context or you could store the pixel values in array variables. Most macros that tackle this problem such as Michael's on that other recent thread take a higher level approach, calling commands and plugins to duplicate, translate offsets, and combine. If you want to manipulate the pixels yourself a Java plugin might work better. (Here's some one else doing this with IJ macro http://www.flickr.com/photos/hortonheardawho/7865007812/ ) Aivar On 12/20/12, Daddymoen wrote: > To All, > > Been thinking about this some more and would like to run an idea past more > experienced folks. I'm not familiar enough with ImageJ macros to know if > this idea is possible. Feedback on this proposed, alternate method would be > appreciated: > > 1. Create a new, "empty" 8-bit RGB image of exactly the same width and > height (in pixels) as my Bayer Raw image and save it as some name, like > maybe EmptyRGB.tiff or EmptyRGB.jpg > > 2 Run a macro in which I: > 2a. Open my 16-bit, Bayer Raw image which has only a single pixel > intensity value at each pixel location. > 2b. Open my 8-bit, EmptyRGB.Tiff image which has three values per pixel, > one r, one g and one b. > > 3. With both of these images simultaneously open. > > 4. Use a "for/next type" loop to read the single pixel value in the Bayer > Raw image (to a variable) starting at location (0,0) > > 5. Use this variable in an algorithm (similar to a LUT) to select rgb > values for a specific color (for example 255, 0, 0 for Red). (Note: I think > I can handle this part) > > 6. Then somehow (setColor(r,g,b)?) insert these selected rgb values into > the newly created, "empty" 8-bit RGB image at location (0,0) > > 7. Repeat this loop until all the pixel locations in the 16-bit Bayer Raw > image have been used to psuedo-color all the corresponding locations in the > 8-bit RGB image. > > 8. Then save the pseudo-colored 8-bit RGB image as something like, > BayerColored.Tiff > > This approach sort of uses the Bayer Raw file as if it is an array of > values, but it's actually just a 16-bit image file. It's probably a typical > novice's, brute force approach that could be more elegantly done by a more > experienced person, if it can work at all. Hopefully my description conveys > the concept. > > I think I can easily create the "empty" 8-bit RGB file of the correct > dimensions by just using DCRaw to convert a RAW file from the same camera > into an ordinary, demosaiced and interpolated RGB file. As preparation I > might even create a macro to change all the pixels in this empty file to > black (0,0,0) or some other color by using setColor(r,g,b) so it doesn't > contain any real image's data. > > So, is this approach possible? If so, any clues about how actually do it? > The part I am not sure about is how to have both images simultaneously open > and then go back and forth between reading the Bayer Raw image pixel, > selecting the rgb values with my algorithm, and writing the algorithm result > to the RGB image. > > I look forward to comments and suggestions. > > Daddymoen > > > > -- > View this message in context: http://imagej.1557.n6.nabble.com/Using-setColor-r-g-b-to-pseudocolor-Bayer-Raw-Image-tp5001221p5001235.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html ... [show rest of quote] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by Daddymoen
>I think I can easily create the "empty" 8-bit RGB file of the correct
>dimensions by just using DCRaw to convert a RAW file from the same camera >into an ordinary, demosaiced and interpolated RGB file. As preparation I >might even create a macro to change all the pixels in this empty file to >black (0,0,0) or some other color by using setColor(r,g,b) so it doesn't >contain any real image's data. It's easy to create a second image of the same size as follows: // examine source sourceTitle = getTitle(); getBoundingRect(x, y, width, height); // make copy destTitle = sourceTitle + " deBayered"; newImage(destTitle, "RGB", width, height, 1); // type "RGB"; depth 1 Aivar On 12/20/12, Daddymoen wrote: > To All, > > Been thinking about this some more and would like to run an idea past more > experienced folks. I'm not familiar enough with ImageJ macros to know if > this idea is possible. Feedback on this proposed, alternate method would be > appreciated: > > 1. Create a new, "empty" 8-bit RGB image of exactly the same width and > height (in pixels) as my Bayer Raw image and save it as some name, like > maybe EmptyRGB.tiff or EmptyRGB.jpg > > 2 Run a macro in which I: > 2a. Open my 16-bit, Bayer Raw image which has only a single pixel > intensity value at each pixel location. > 2b. Open my 8-bit, EmptyRGB.Tiff image which has three values per pixel, > one r, one g and one b. > > 3. With both of these images simultaneously open. > > 4. Use a "for/next type" loop to read the single pixel value in the Bayer > Raw image (to a variable) starting at location (0,0) > > 5. Use this variable in an algorithm (similar to a LUT) to select rgb > values for a specific color (for example 255, 0, 0 for Red). (Note: I think > I can handle this part) > > 6. Then somehow (setColor(r,g,b)?) insert these selected rgb values into > the newly created, "empty" 8-bit RGB image at location (0,0) > > 7. Repeat this loop until all the pixel locations in the 16-bit Bayer Raw > image have been used to psuedo-color all the corresponding locations in the > 8-bit RGB image. > > 8. Then save the pseudo-colored 8-bit RGB image as something like, > BayerColored.Tiff > > This approach sort of uses the Bayer Raw file as if it is an array of > values, but it's actually just a 16-bit image file. It's probably a typical > novice's, brute force approach that could be more elegantly done by a more > experienced person, if it can work at all. Hopefully my description conveys > the concept. > > I think I can easily create the "empty" 8-bit RGB file of the correct > dimensions by just using DCRaw to convert a RAW file from the same camera > into an ordinary, demosaiced and interpolated RGB file. As preparation I > might even create a macro to change all the pixels in this empty file to > black (0,0,0) or some other color by using setColor(r,g,b) so it doesn't > contain any real image's data. > > So, is this approach possible? If so, any clues about how actually do it? > The part I am not sure about is how to have both images simultaneously open > and then go back and forth between reading the Bayer Raw image pixel, > selecting the rgb values with my algorithm, and writing the algorithm result > to the RGB image. > > I look forward to comments and suggestions. > > Daddymoen > > > > -- > View this message in context: http://imagej.1557.n6.nabble.com/Using-setColor-r-g-b-to-pseudocolor-Bayer-Raw-Image-tp5001221p5001235.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html ... [show rest of quote] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by Aivar Grislis
Aivar,
Thank you for sharing your knowledge. Yes looping over the pixels in both the source and destination images as you describe is how I, as a novice, am able to understand the concept of a solution using macros. I realize from your post that using macros is a kind of slow, clunky way to accomplish the task, but it points in a direction I grasp and can make some progress with. My project would no doubt benefit from me taking the time to learn Java programming to accomplish this with plugins. If my quick and dirty macro approach shows good evidence of making the phantom leaf structures I'm looking for visible I will probably bite the bullet and learn Java plugin programming. Maybe the experience with macro approach will help learning that. From your other post I understand enough about how to create an RGB image file (identical size-wise to my Bayer Raw image) to figure out the rest of the details. I feel like I can get back to work and make some progress again. Thanks for that. Daddymoen PS: Not sure the images below will display well enough to see evidence of the phantom leaf structures I am trying to image in my project. The first image shows a leaf before cutting out a small rectangular section. The second image is of the same leaf after removing the rectangular section and processing the image data to pseudo color pixel intensity variation of the area where the leaf no longer physically exists. This was done with my old FilterMeister/PhotoShop plugin method using 8-bit, lossy, JPG image files. I think that using 16-bit Tiff images and some changes I now use in taking the pictures (that improve resolution) have a chance of yielding better results. ![]() ![]() -----------------------------------
... [show rest of quote]
Imagination is more important than knowledge. Albert Einstein
|
Free forum by Nabble | Disable Popup Ads | Edit this page |