How to detect %Red/Red pixels

Discussion in 'The Projects Forum' started by ccst91, Dec 7, 2013.

  1. ccst91

    Thread Starter New Member

    Dec 7, 2013
    6
    0
    Hey everyone
    I'm a biomedical student working on a project and am kind of stuck.
    The project involves the detection of blood in the urine.
    The idea is to calculate the percentage red or number of reddish pixels and correlate that to a blood concentration. The correlation is something that shouldn't be too hard but I'm having trouble on the best way to get the %red/ red pixels.

    Initially I was going to create a smartphone application that would take a picture, and process the image to obtain the %red. The problem with this is that not all phone cameras are the same.

    I was suggested to get some sort of photodetector to do this. Does anyone have any idea of how this would work? Would it directly get the %red or would it take a picture and I would have to output that to something like Matlab to process?
    I was looking at some USB CMOS cameras that are compatible with Matlab, but I'm not sure if they will work.. don't want to spend $250 on it before knowing.
    Here's one I was looking at : http://www.theimagingsource.com/en_US/products/oem-cameras/usb-cmos-color/

    Any ideas or help would be greatly appreciated.
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,022
    Could you include a color reference in the photo and correct to that?
     
  3. ccst91

    Thread Starter New Member

    Dec 7, 2013
    6
    0
    You mean sticking with the phone application idea and using a color reference in there to correct to?
    I may be able to.. I have no experience creating app's but that is another idea that was suggested.
    If i had like a red card or something that should be 100% red, and use that as a standard. I'm not sure what other camera spec's might be different though.

    When the phone outputs RGB vales, is the Red value based on number of pixels? Because then I could also have to control to make sure the resolution(i think thats the right word? or whatever to make sure the total # of pixels) is the same.
     
  4. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    The problem is that th eamount of "red" will depend on the light source AND items in the environment and background. Remember a camera captures the LIGHT, not the object!

    I think the idea is a bit of a bust, unless you have a special light, in a small controlled special environment (like a device) AND it has been calibrated.

    Even then, bilirubin (the chemical that makes pee yellow-brown at times) will give some "red" reading as browns have a large red component.
     
  5. ccst91

    Thread Starter New Member

    Dec 7, 2013
    6
    0
    The lighting/environment will not be an issue. The sample will be placed on top of a light source that I will design, and no other light will be present (dark room). So lighting will be constant.

    I haven't looked into how much billirubin varies from individual to individual but calibration will be done by testing several(probably around 100) samples of known blood concentrations in urine. I just need a way to get the %red
     
  6. WBahn

    Moderator

    Mar 31, 2012
    17,716
    4,788
    If you have a large collection of test samples that span the range of interest in terms of the amount of blood in the urine, then you don't really need to get the red percentage, per se. You just need to find something that correlates well with the variable of interest -- that may well be red or it may be something else entirely.

    I'm sure there are lots of ways to get a %red metric, each with it's pros and cons. I most certainly am NOT an image processing guy, so take this with an appropriately sized grain of salt. The first thing that comes to mind is that the luminance (gray scale) of a pixel can be defined to be the Pythagorean sum of the colors, or

    Y = sqrt(R^2 + G^2 + B^2).

    You can then define the %red to be

    %red = R/Y = 1/sqrt[1 + (G/R)^2 + (B/R)^2]

    You can them find the average of this over the region of interest.

    It might be better to, instead, use a metric that is based on the fraction of pixels that exceed a certain threshold in terms of %red.

    There are a lot of different things you can try. I would recommend taking pictures of all of your specimens with several different cameras. The pick a few cameras and maybe ten percent of the specimens and set all of those images aside. With the remaining images, start playing around with various metrics and see what kind of correlations you get. Once you think you have something, go to the images that were set aside and see if it works will on those. If it does, you're on the right track. If it doesn't, then you are barking up the wrong tree.
     
  7. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    The RGB value is for each pixel. You get the image data from the camera and scan through it pixel by pixel, for each pixel you will have RGB values. You need a threshold ratio between Red/Blue and Red/Green at which you decide if it is blood. As others have suggested you could do this from a known reference (say a red card or filter in one corner of the image) but to start with I would just do some trials with manually set thresholds. If you have a constant light source and sufficient contrast between the urine and blood you may not need too much calibration between phones.
     
  8. wayneh

    Expert

    Sep 9, 2010
    12,093
    3,030
    Are we talking about gross hematuria? I mean, the proposed method is basically a slightly automated version of what we would do with our eyes. It cannot do more, for instance it will not detect individual red blood cells in the urine. (Microscopic hematuria.) It cannot easily discriminate the presence of a pigment (beet juice) that might look like blood.

    Since we're just duplicating what our eyes do, I think all you can really do is quantify the "color". One of those fancy color meters you use to calibrate a monitor comes to mind. Basically you want to look for a high ratio of absorbance at the hemoglobin wavelength to the absorbance at other, non-heme wavelengths. Human eyes are darn good at this but a machine might do a better job at quantitation.

    If I was doing this in the lab, I'd look to use a flow cytometer. This device sends liquids through a tiny orifice with a laser pointed at it. It can effectively "see" the individual particles passing through the orifice, and characterize them for size, color, and other properties.
     
  9. #12

    Expert

    Nov 30, 2010
    16,257
    6,757
    I know I'm late to the party, and I'm not able to implement these ideas, but...If a signal sent to a computer monitor has a red, green, and blue channel, just finding the magnitude of the red channel would be a start. If a red filter was used between the sample and the detector, the brightness alone would be a clue.

    That's my two cents. If that's only worth 2 cents, so be it. I'm just tossing ideas up. Smarter people than I will have to decide if they are of any value.
     
  10. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
  11. BReeves

    Member

    Nov 24, 2012
    412
    64
    You are on the right track, the camera you linked should would work great. You will need to capture the image to an RGB bitmap then just scan the pixels to see what color each pixel is by analyzing the RGB values.

    Looks like they have a software development kit (SDK) that is compatible with most software development environments. Time to learn a programing language :)

    I have done something like you are after for a different reason but I use Borland C++ Builder which isn't real common.

    On second thought you can do what you need with a $69.00 USB microscope. Just capture the image to a bitmap file using the software that comes with the camera then open the bitmap file with the software you write to do the analyzing.

    Better yet, just found these on eBay.. You do not need high resolution.
    http://www.ebay.com/bhp/usb-microscope-500x
     
    Last edited: Dec 8, 2013
  12. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    If you are going to need a custom lighting fixture and shield from room lights etc, then why use a camera? You have no need for resolution.

    There are a lot of colour sensing chips on the market that seem to me to be a better solution. These usually have 4 sesning elements within; white, red, green, blue. Some output a voltage for the red channel, some output a frequency.
     
  13. wayneh

    Expert

    Sep 9, 2010
    12,093
    3,030
    Good info here. Looks like hemoglobin peaks ~420nm.

    A traditional flatbed scanner might be a good tool here. They have specific routines (such as warming up the light source) for maintaining color accuracy.
     
  14. ccst91

    Thread Starter New Member

    Dec 7, 2013
    6
    0
    Yes gross hematuria. The idea is just to be able to quantify the concentration. Going with the idea of hemoglobin wavelength, it should be possible to mount a photodiode opposite the direction of the light source and place a red filter on it at the hemoglobin wavelength right? I don't know much about photodiodes but it would output a voltage that I could then correlate to a blood concentration?
     
  15. ccst91

    Thread Starter New Member

    Dec 7, 2013
    6
    0
    That camera I linked is compatible with Matlab which I am pretty proficient in. I just dont know much about the camera at all so I wanted to make sure before I bought something that costs that much.
    The microscope idea does seem good but I'm not sure how well it would go over considering I would basically just be using a device that already exists and simply writing a few lines of code.
     
  16. ccst91

    Thread Starter New Member

    Dec 7, 2013
    6
    0
    Yes I think thats a really good point and one that was made to me. I am going to be controlling the environment so there is no need to use a camera. I am not familiar with photodetectors or the chips you are talking about which is why I am here. Do you have a link for one as an example?
    If I could find one that outputs a voltage for the red channel, I can simply calibrate with several samples to correlate voltage to concentration.
     
  17. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Try a Digikey search, they have lookup tables of different colour sensors, you can pick one that suits your needs. :)
     
  18. wayneh

    Expert

    Sep 9, 2010
    12,093
    3,030
    I really don't think you'll be happy with just one wavelength. I think you'll need to have a 2nd wavelength to correct for background color (non heme pigment) and to correct for clarity. Turbidity can appear as absorption, simulating a pigment - you need to produce a clarity-corrected color.

    I spent years in the corn syrup business, and in that industry they talk about "color corrected clarity". If you define clarity as percent transmittance at a wavelength, you have to estimate how much absorbance at that wavelength is due to the color alone. A solution can be crystal clear but colored, or uncolored but not crystal clear. A spectrophotometer with one wavelength cannot discriminate these cases.
     
    THE_RB and #12 like this.
Loading...