title: Changing Color Space from RGB to HSV after segmentation (OpenCv Python)
body: <p>I am segmenting an image and then converting it into HSV format. But after converting it into HSV and separating out each of the channels, the granularity of the segmented region is lost. Following is the segmentation code.</p>
  
  <pre><code>import cv2
  from os import listdir
  from os.path import isfile, join
  from mpl_toolkits.mplot3d import Axes3D
  import numpy as np
  import matplotlib.pyplot as plt
  
  path = "C:/Users/Intern/Desktop/dataset/rust images/"
  files_test = [f for f in listdir(path+ 'Input/') if isfile(join(path+ 'Input/', f))]
  for img_name in files_test:
      img = cv2.imread(path + "Input/" + img_name)
      gray_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
      gray_blur = cv2.GaussianBlur(gray_img, (7, 7), 0)
      adapt_thresh_im = cv2.adaptiveThreshold(gray_blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 20)
      max_thresh, thresh_im = cv2.threshold(gray_img, 100, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
      thresh = cv2.bitwise_or(adapt_thresh_im, thresh_im)
      kernel = np.ones((3,3),np.uint8)
      opening = cv2.morphologyEx(thresh,cv2.MORPH_OPEN,kernel, iterations = 2)
      sure_bg = cv2.dilate(thresh,kernel,iterations=2)
      img[sure_bg == 0] = [0,0,0]
      cv2.imwrite(path + "Segmented/" + img_name, img)
  </code></pre>
  
  <p>Following is the input image.<a href="https://i.stack.imgur.com/gGD39.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gGD39.jpg" alt="Input"></a> </p>
  
  <p>Following is the corresponding output.</p>
  
  <p><a href="https://i.stack.imgur.com/HE8Ct.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HE8Ct.jpg" alt="Output"></a>
  Now, In a new program I try to read this output and convert it into HSV format. Following is the code.</p>
  
  <pre><code>import cv2
  from os import listdir
  from os.path import isfile, join
  import numpy as np
  
  path = "C:/Users/Intern/Desktop/dataset/rust images/"
  files_test = [f for f in listdir(path+ "Segmented/") if isfile(join(path+ "Segmented/", f))]
  for img_name in files_rust:
      img = cv2.imread(path + "Segmented/" + img_name)
      img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
      print img_hsv.shape
      h, s, v = cv2.split(img_hsv)
      cv2.imshow("hsv image", s)
      cv2.waitKey(0)
  </code></pre>
  
  <p>Following is the output after converting into HSV.
  <a href="https://i.stack.imgur.com/nYadC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nYadC.jpg" alt="Output"></a></p>
  
  <p>We can observe that compared to the original one the granularity of the black spaces has reduced. How can I solve this problem? </p>
  
  <p>Thanks for the help.</p>
  
  <p>Photograph taken from <a href="http://www.istockphoto.com/in?esource=SEM_IS_GO_IN_Photograph_Stock_Head_EN_Broad&amp;kw=IN_Photograph_Broad_%2Bstock+%2Bphotograph_b&amp;kwid=s_43700009930191235_dc&amp;pcrid=92932651095&amp;esource=SEM_IS_GO_IN_Photograph_Stock_Head_EN_Broad&amp;kw=IN_Photograph_Broad_%2Bstock+%2Bphotograph_b&amp;kwid=s_43700009930191235_dc&amp;pcrid=92932651095&amp;gclid=CjwKEAjwsLTJBRCvibaW9bGLtUESJAC4wKw1eKFKhcVHU0WEuvrrEG2u6iz1RSVSRYm_0rJoXIIMjRoC3Zvw_wcB&amp;gclsrc=aw.ds" rel="nofollow noreferrer">4</a></p>