Answers.Body: <p>Your solution is pretty much on spot. It corresponds to the <a href="https://en.m.wikipedia.org/wiki/YUV" rel="nofollow noreferrer">YUV scheme</a> used in television and designed to match human perception characteristics. As you already noticed, such an encoding wouldn't suffer from discontinuities.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-27T21:04:27.397Z
Answers.Text: And its cousin YCbCr. Which apparently in some contexts means the same thing.
Answers.UserDisplayName: NikoNyrh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-27T20:37:22.560Z
Answers.LastActivityDate: 2020-05-27T20:37:22.560Z
Answers.UserDisplayName: Hans-Martin Mosner
Body: <p>I was thinking about training a neural network to colourize images. The input would be the luminosity/value for each pixel, and the output would be a hue and/or saturation. Training data would be easily obtained just by selecting the luminosity/value channel from a full colour image.</p>
  
  <p>Suppose all channels are scaled to 0.0-1.0, there is a problem with pixels whose hue is nearly 0.0 or nearly 1.0.</p>
  
  <ul>
  <li>The input data may have sharp discontinuities in hue which are not visible to the human eye. This is an unstable, illusory boundary which seems like it would destablilize the training.</li>
  <li>Also if the network outputs a value of 1.001 instead of 0.001 then this should NOT be penalised since.</li>
  </ul>
  
  <p>Possible workarounds might be to preprocess the image to remap e.g. 0.99 to -0.01 if that pixel is near a region dominated by near-0 hues, or similarly to to remap e.g. 0.01 to 1.01 if that pixel is near a region dominated by near-1 hues. This has its own problems. Similarly, outputs could be wrapped to the range 0-1 before being scored.</p>
  
  <p>But is there a better way to encode cyclic values such as hue so that they will naturally be continuous?</p>
  
  <p>One solution I thought of would be to treat (hue,saturation) as a (theta,r) polar coordinate and translate this to Cartesian (x,y) and have that be the training target, but I don't know how this change of colour space will affect things (it might be find, I haven't tried it yet).</p>
  
  <p>Are there alternative colour representations which are better suited to machine learning?</p>
  
Tags: <neural-networks><machine-learning>
Title: How could a NN be trained to output a cyclic (e.g. hue) number?
UserDisplayName: spraff
ThreadText: # How could a NN be trained to output a cyclic (e.g. hue) number?
  
  (Asked by: username_0 on 2020-05-27)
  
  I was thinking about training a neural network to colourize images. The input would be the luminosity/value for each pixel, and the output would be a hue and/or saturation. Training data would be easily obtained just by selecting the luminosity/value channel from a full colour image.
  
  Suppose all channels are scaled to 0.0-1.0, there is a problem with pixels whose hue is nearly 0.0 or nearly 1.0.
  
  * The input data may have sharp discontinuities in hue which are not visible to the human eye. This is an unstable, illusory boundary which seems like it would destablilize the training.
  * Also if the network outputs a value of 1.001 instead of 0.001 then this should NOT be penalised since.
  
  Possible workarounds might be to preprocess the image to remap e.g. 0.99 to -0.01 if that pixel is near a region dominated by near-0 hues, or similarly to to remap e.g. 0.01 to 1.01 if that pixel is near a region dominated by near-1 hues. This has its own problems. Similarly, outputs could be wrapped to the range 0-1 before being scored.
  
  But is there a better way to encode cyclic values such as hue so that they will naturally be continuous?
  
  One solution I thought of would be to treat (hue,saturation) as a (theta,r) polar coordinate and translate this to Cartesian (x,y) and have that be the training target, but I don't know how this change of colour space will affect things (it might be find, I haven't tried it yet).
  
  Are there alternative colour representations which are better suited to machine learning?
  
  **Tags:** neural-networks, machine-learning
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-05-27. Score: 2
  
  Your solution is pretty much on spot. It corresponds to the [YUV scheme](https://en.m.wikipedia.org/wiki/YUV) used in television and designed to match human perception characteristics. As you already noticed, such an encoding wouldn't suffer from discontinuities.
  
  > **Comments:**
  > **username_2**: And its cousin YCbCr. Which apparently in some contexts means the same thing.  
  
  ---
  
  