RGB Images: extracting individual channels
sleepingawake86
I am doing research with RGB images and most of the information I want is in the blue channel of the RGB image. I tried
ImageTransform rgb2gray
to convert the RGB photo into gray and run analysis, but the result is very noisy from the red and green channel contributions.
The helpfile also recommended
gray2DWave=c1*image[p][q][0]+c2*image[p][q][1]+c3*image[p][q][2]
but every time I try that igor returns an error.
The last thing I attempted, also from the helpfile was
Make/O/N=3 scaleWave={c1,c2,c3}
ImageTransform/D=scaleWave scalePlanes image
ImageTransform sumPlanes M_ScaledPlanes
ImageTransform/D=scaleWave scalePlanes image
ImageTransform sumPlanes M_ScaledPlanes
but that too only returned errors.
I know I can use the Lineprofile macro under the built in Image Analysis package, but I am looking to do batch analysis, so I want a process that doesnt involve plotting the image and using the GUI.
I just want to be able to plug in the wave name and have the program do it automatically.
What errors did this cause? You have to make sure that c1, c2, and c3 are defined as local variables (if you do this from a user-defined function) or global variables (if you do this from the command line). So, for example, here is what you would type on the command line to do this:
variable c2 = 0.587
variable c3 = 0.114
Duplicate/O/R=[][][0] image, gray2DWave
Redimension/N=(-1, -1, 0) gray2DWave // Convert wave from a 1 layer 3D wave to a 2D wave
gray2DWave=c1*image[p][q][0]+c2*image[p][q][1]+c3*image[p][q][2]
This should give you the same results that using ImageTransform with the rgb2gray keyword would give you (assuming that image is the name of a 3D RGB wave). You will need to adjust the values of c1, c2, and c3 for your purpose.
I'm guessing that you didn't define c1, c2, and c3, as I mentioned above.
You haven't really said what it is that you actually want to do. If you want to extract *only* the blue channel from a 3D wave into a 2D wave, you can do this:
The output of ImageTransform in this case, M_ImagePlane, would be a 2D wave containing only the data in the 2nd (blue) layer of the original wave.
July 5, 2010 at 03:09 pm - Permalink
You need to extract the Blue channel as a plane from the image
ImageTransform/p=2 getPlane RGBImageWave
Use p=0 for Red, p=1 for Green and p=2 for Blue. The wave output is called M_ImagePlane.
From here you can call the image analysis commands, such as thresholding, eg at 64 levels
Extracting a line profile from this channel can be done by specifying the row number in the M_ImagePlane 2D wave in a function like this:
wave image
variable x
Variable rows
rows=DimSize(image,0)
Make/O/N=(rows) SliceBlue
imagetransform/p=2 getplane image
SliceBlue=M_ImagePlane[p][x]
End Function
Hope this helps,
Jason.
July 5, 2010 at 03:22 pm - Permalink