1

I am new to image processing and opencv, but recently I was working on edge detection ideas and I have questions regarding it:

  • Can canny be applied on colored images directly without converting it to grayscale? and would this affect the results? I tried it (using c++ opnencv function) there was no errors or problems and the results were different from the ones after I changed the images to grayscale.

  • I read that for colored images I should apply canny on each channel separately and then combine the results.. okay let's suppose that I have 3 results for each channel how can I combine them together to get the final result?

  • Is it true processing the images in grayscale faster than colored ones since in the later we have 3 channels (logically it seems yes but there was no reference comparing between pros and cons for each method; all I have is that the grayscale is faster while for image segmentation colored images can be more informative) in concept of edge detection is it better to use colored images or not?

yaminoyuki
  • 293
  • 1
  • 11
  • Does this answer your question? [Can Canny in OpenCV deal with both grayscale and color images?](https://stackoverflow.com/questions/40725804/can-canny-in-opencv-deal-with-both-grayscale-and-color-images) – Burak Oct 24 '20 at 18:26
  • @Burak thank you, but it answers only the first one, not the second and the third – yaminoyuki Oct 24 '20 at 18:34

1 Answers1

0

If you accept python, then you could do:

For 2nd question:


    1. Separate channels using split method for separating the channels, apply each channel Canny with different threshold levels, then use merge method for combining the result.

  • import cv2   
    
    img = cv2.imread("grl.jpg")
    (B, G, R) = cv2.split(img)
    B_cny = cv2.Canny(B, 50, 200)
    G_cny = cv2.Canny(G, 50, 200)
    R_cny = cv2.Canny(R, 50, 200)
    img_cny = cv2.merge([B_cny, G_cny, R_cny]) 
    
  • Result:


  • enter image description here enter image description here

  • Possible Question: Why split returns B, G, and R?

  • Answer: Opencv read images in (BGR) format, therefore split returns (B, G, R) format

  • You could also directly apply to the image (Thanks to @fmw42):

  • Result:

  • enter image description here

For 3rd question:


  • Yes processing gray-scale images are much faster than the colored images.

  • We see images with different colors, but what computer see is a matrix of values:

    • For instance:

      • 25 45 67 37 90 ..
        56  .
        46     .     
        34        .
        13           .
        .
        .
        
      • Each cell in the matrix can be vary in the range between 0-255. For grey-scale images (matrix) there is only 1 channel, for color images there are 3 channels (matrix)

      • Therefore, you can think it as calculating a single-matrix (grey) is faster than calculating 3-matrixes (image)

Ahmet
  • 7,527
  • 3
  • 23
  • 47
  • thank you,so merging the channels is acceptable, I wasn't sure if that is acceptable – yaminoyuki Oct 25 '20 at 06:43
  • I do not see any limitations that restrict canny to grayscale images. See https://docs.opencv.org/4.1.1/dd/d1a/group__imgproc__feature.html#ga04723e007ed888ddf11d9ba04e2232de – fmw42 Oct 25 '20 at 07:03
  • Thanks for the warning @fmw42 appreciated. – Ahmet Oct 25 '20 at 07:48