2

Here's what I would like to do:

I have an image of rice leaf. I have another image of rice leaf that got brown color spots on the leaf. What I want to do is separate the color pixels that are not common for two images using opencv.(color of the spots can be vary)

I tried to do this using histogram intersection. But only managed to find number of pixels common between two images.

Is there any way to do this using opencv? Please be me kind enough to help me.

tdk
  • 29
  • 3
  • Separate in which way? You could iterate through all pixels (two for loops, outer loop for rows, inner for columns), find out, if two pixels at current position are different, and do what you need to do.. – RhinoDevel Jul 05 '15 at 19:28
  • @RhinoDevel need to create a new image from those non common pixels. – tdk Jul 05 '15 at 19:31
  • Create a third (output) image before your comparing loop(-s). If the current pixels in the loop at a position are equal, put "black" to the output image (R = 0, G = 0, B = 0) - or the input value, if you like. If the colors differ, add white (or maybe green..) to the output at that position (for example). – RhinoDevel Jul 05 '15 at 19:34
  • I find your question quite unclear. Do you want to generate a list of all the colours in `image A` and a list of all the colours in `image B` and then find the colours that only occur in one of the two lists but not both? Or do you want to look at each location in the two images and note whether the colours are the same or not at each location? Or something else altogether? – Mark Setchell Jul 05 '15 at 21:31
  • @MarkSetchell I want to extract colors that occur in image A and not occur in image B.(color pixels not belong to color pixels intersection between image A and image B ) – tdk Jul 06 '15 at 06:52
  • you probably should add example of 2 source images and wanted output to be clear... so we see what you are dealing with because there are issues that depends on the form of input and output changing the possible answer in many ways ... – Spektre Jul 06 '15 at 06:58
  • Add some images for better understanding. – Pervez Alam Jul 07 '15 at 12:10

1 Answers1

0

if the 2 images match perfectly

  • if they match use RhinoDevel approach:
  • so loop through all pixels of first image
  • and compare each pixel with corresponding pixel from second image
  • if the difference is higher then treshold
  • you found not matching Pixel and do what you need to do
  • like add pixel to some output map or recolor (brown) pixel to color from first image or whatever

if the 2 images does not match

  • so you just got some reference leaf image and the processed image can have any position/rotation skew
  • create list of colors per each image
  • sort them ascending by color
  • cross compare booth lists
  • if any color is in list2 but not in list1
  • then recolor/copy all pixels that contains such color in/from image2
  • this approach is slower O(xs*ys*n)
  • xs,ys is image 2 resolution and n is number of non common colors

[Notes]

  • RGB is usually fine but may be you got better result on HSV color space
  • in HSV you can compare all 3 parameters or just few of them like ignoring V value...
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Yes I hope to use HSI color model. Ho can i create a list of colors of a image? Do i need to loop through all pixels for that or is there any efficient way for that. – tdk Jul 06 '15 at 07:10
  • @tdk yes you need to loop through all pixels. OpenCV has functions to obtain histogram but I do not use OpenCV may be this will help: [HSV histogram](http://stackoverflow.com/a/29286584/2521214). (in question is some code to obtain HSV histogram) From histogram you just need info if color is present or not. So if there is not too much colors then it is better to have a list of present colors instead of map of flags covering all possible colors which could be a big chunk of memory slowing all down considerably... – Spektre Jul 06 '15 at 07:18
  • I have already obtain HS histograms of both images. Through histogram intersection i can find number of common pixels between two images. How can i extract pixels that are not belong to intersection? – tdk Jul 06 '15 at 07:52
  • @tdk simply loop through all pixels, and on each pixel look into your not common color list. if it is present there then do something with the pixel (set pixel in output map, recolor/copy pixel or what ever) ... so you need not the intersection of colors but the colors that are left from it ... (it is faster to loop trough smaller list) ... 3 `for` loops and single `if` statement ... – Spektre Jul 06 '15 at 08:09