English subtitles

← Grayscale - Intro to Java Programming

Get Embed Code
6 Languages

Showing Revision 5 created 05/25/2016 by Udacity Robot.

  1. In the olden days, cameras couldn't record glorious color, they only had grey.
  2. And sometimes we want to take a photograph and turn it back into grey to give
  3. it that old fashioned effect. Now, you might thing that all you'd have to do is
  4. average the red, green, and blue values. But it's not quite that simple. As it
  5. turns out, the receptors that we have in our eyes have different sensitivities
  6. to colors. And what you actually have to do is take the red, green and blue
  7. values weighted by these factors, and then turn them into grey. And then, when
  8. you're done with that, you can set red to these value green and blue, because
  9. they're all the same, that's what makes the color grey. And then, you're done.
  10. But we have the same problem that you just saw. Red, green, blue are integers.
  11. These weighing constants are fractional numbers. So, the whole expression is a
  12. fractional number. And I want to put it back into an integer. So, the solution
  13. is again, to inject a cast, put this expression in parentheses and put
  14. parenthesis int before that. And then, you get it truncated down to the nearest
  15. integer. Once again, I'd like you to try that, so you can see it with your own
  16. eyes. Go ahead. Again, in the color class, implement a new method. In this
  17. case, it's the turnGray method. Take the red, green and blue values, combine
  18. them to a gray value using the equation that you just saw. Make sure that you
  19. get an integer. And then, take that integer and put it back into red, green and
  20. blue. Go ahead and do it now.