title: Color thresholding an HLS jpeg image
body: <p>I am trying to color threshold a jpeg image so that I can keep the lane lines and hopefully get rid of the rest of the world.
  I am reading the image using <code>cv2</code> as follows:</p>
  
  <pre><code>test_image = cv2.imread(myimage)
  #convert to RGB space from BGR
  test_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB)
  </code></pre>
  
  <p>Then, I convert the test_image to HLS color space, to retain l channel as below:</p>
  
  <pre><code>def get_l_channel_hls(img):
      # Convert to HLS color space and separate the l channel
      hls = cv2.cvtColor(img, cv2.COLOR_RGB2HLS).astype(np.float)
      l_channel = hls[:,:,1]
      return l_channel
  </code></pre>
  
  <p>Then I apply some thresholds to this l channel and replace the pixel values by 0 or 1, so that I can retain only the pixels I want. (I will later multiply these values by 255, to make the retained pixels appear white)</p>
  
  <pre><code>def get_color_channel_thresholded_binary(channel, thresh=(0,255):
      # Threshold color channel
      print("min color threshold: {}".format(thresh[0]))
      print("max color threshold: {}".format(thresh[1])) 
      binary = np.zeros_like(channel)
      binary[(channel &gt; thresh[0]) | (channel &lt;= thresh[1])] = 1
      return binary
  </code></pre>
  
  <p>Then, I take this binary map and replace the retained pixels with 255</p>
  
  <pre><code>def get_overall_combined_binary(binary1):
      grayscaled_binary = np.zeros_like(binary1)
      grayscaled_binary [(binary1 == 1)] = 255
      return grayscaled_binary
  </code></pre>
  
  <p>And I display this binary using matplotlib pyplot as below:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  #grayscaled_binary = # get the grayscaled binary using above APIs
  imshow(grayscaled_binary, cmap='gray')
  </code></pre>
  
  <p>What I am observing here is rather strange. The image appears all black for ANY values for which <code>thresh[1] &lt; thresh[0]</code>. i.e. maximum threshold is LESS than the minimum threshold. And I have no clue as to why this is happening.</p>
  
  <p>I have reviewed the code a few times now and I don't see any bugs in it. The only difference between the code I have pasted here vs the one I am using is that, I'm using IPython widgets in Jupyter notebook to interact.</p>
  
  <p>I'd greatly appreciate any help or insight with this topic.
  I'm also attaching two examples of what I am talking about.
  Thanks in advance.<a href="https://i.stack.imgur.com/LvJQU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LvJQU.jpg" alt="Failure Scenario"></a>
  <a href="https://i.stack.imgur.com/e24HM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e24HM.jpg" alt="enter image description here"></a></p>