1

i am working on a project using opencv in python in which i want to detect the clouds in an image. i have tried a lot of things but i am stuck.i couldn't find the exact range of cloud color values for hsv color space. this is the code i have tried. the following code detect some of the clouds but not all.this is the code.i have also attached an image which i am getting from this code.

enter image description here

import cv2
import numpy as np

img = cv2.imread('E:/sky.jpg', 1)
hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)

white = np.array([255, 255, 255])
lowerBound = np.array([30,30,30])

mask = cv2.inRange(hsv, lowerBound, white)

res = cv2.bitwise_and(img, img, mask=mask)
cv2.imwrite("E:/clouds.jpg",res)

cv2.imshow("mywindow",res)

cv2.waitKey(0)
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Tehseen
  • 115
  • 2
  • 14
  • You assign a value of [255,255,255] for white in HSV colorspace? HSV is not RGB –  Nov 14 '17 at 10:52
  • if i change [255,255,255] to [0,0,100] which is hsv for [255,255,255] then it make it all black. the image become all black..is there any problem with my code? – Tehseen Nov 14 '17 at 10:58
  • "If I change..." are you blindly trying combinations of numbers? Where does the [30,30,30] come from? What color does it represent in HSV (remember you are not in RGB) –  Nov 14 '17 at 11:02
  • [30,30,30] is a dark greenish color in HSV, nothing to do with your sky or clouds color –  Nov 14 '17 at 11:04
  • 1
    Possible duplicate of [Tracking white color using python opencv](https://stackoverflow.com/questions/22588146/tracking-white-color-using-python-opencv) – GPPK Nov 14 '17 at 12:03
  • then why did it give me that black area which is cloud? – Tehseen Nov 14 '17 at 12:14
  • what should i do? kindly help me with my code to detect the clouds in that attached image – Tehseen Nov 14 '17 at 12:30
  • @Tehseen Can you share the original image containing clouds? – Jeru Luke Jul 11 '18 at 07:52

1 Answers1

0

Try not changing the image to HSV color space. Remove line

hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)

The rest of the code clearly shows you are working with a RGB color based scheme and you have no idea what HSV is. Frankly speaking, i don't see the need for you to work with HSV color space in the first place. It can be done even with grayscale image representation.

yapws87
  • 1,809
  • 7
  • 16
  • now i understand that i was working with RGB but now i don't know the color range for clouds. i have searched a lot but couldn't find the hsv values to detect clouds. – Tehseen Nov 14 '17 at 14:18
  • and by removing the line of code which convert the image from BGR to HSV is not giving me my desired result – Tehseen Nov 14 '17 at 14:19
  • then you should go and do some research on the function name adaptivethreshold – yapws87 Nov 14 '17 at 14:37