title: RGB to HSV Python, change Hue continuously
body: <p><strong>What I'm trying to do:</strong> continuously change the <em>Hue</em> value of an image, from 0 to 360, saving one image for each Hue.</p>
  
  <p><strong>How I'm trying:</strong> I started by using code I found on <a href="https://stackoverflow.com/questions/22236956/rgb-to-hsv-via-pil-and-colorsys">this link</a>, then modifying it to change the Hue and save the images.</p>
  
  <p><strong>What is the problem:</strong> The code from the link above apparently doesn't save the image as true HSV, because when it merges the image it uses the <em>image mode RGB</em>. But I can't find a way to make it HSV.</p>
  
  <pre><code>def hueChange(img, hue):
      if isinstance(img, Image.Image):
          img.load()
          r, g, b = img.split()
          h_data = []
          s_data = []
          v_data = []
  
          for rd, gr, bl in zip(r.getdata(), g.getdata(), b.getdata()):
              h, s, v = colorsys.rgb_to_hsv(rd / 255., bl / 255., gr / 255.) 
              h_data.append(int(hue))
              s_data.append(int(s * 255.))
              v_data.append(int(v * 255.))
  
          r.putdata(h_data)
          g.putdata(s_data)
          b.putdata(v_data)
          return toRGB(Image.merge('RGB',(r,g,b)))
      else:
          return None
  
  # Don't care about the range indices, they are just for testing 
  for hue in range(1, 255, 30):
      in_name = '/Users/cgois/Dropbox/Python/fred/fred' + str(hue) + '.jpg'
      img = Image.open(in_name)
      img = hueChange(img, hue)
  
      out_name = '/Users/cgois/Dropbox/Python/fred/hue/fred_hue' + str(hue) + '.png'
      img.save(out_name)
  </code></pre>
  
  <p><strong>The last solution I tried:</strong> was to do the conversion as above, and then convert it back to RGB using a similar code to hueChange(...). However, the effect was just that the output images had a *(single)*color overlay on top of them.</p>
  
  <p>Any ideas? Thank you for your time (:</p>