Photo mosaics With Ruby And Yahoo! BOSS


Published on

  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Photo mosaics With Ruby And Yahoo! BOSS

  1. 1. Photo mosaics with Ruby and Yahoo! BOSS Chang Sau Sheong [email_address]
  2. 2. a picture montage made with a large number of photos
  3. 3. Mosaic Photo tile
  4. 4. Master photo Simple algorithm mosaic
  5. 5. Simple algorithm <ul><li>Simple pixel by pixel replacement </li></ul><ul><li>Basic color comparison </li></ul><ul><li>Can have repeating tile photos </li></ul><ul><li>Small photo set source </li></ul><ul><li>Not so great results (but still quite nice)! </li></ul>
  6. 6. What do you need? <ul><li>Ruby </li></ul><ul><li>RMagick (ImageMagick) </li></ul><ul><li>Yahoo! BOSS image search </li></ul>
  7. 7. Algorithm <ul><li>Take a photo (master photo) reduce it to smaller, more manageable size </li></ul><ul><li>Use Y! BOSS to search for photos with the given ‘theme’. Returned photos are our photo tiles </li></ul><ul><li>Get the average color of each photo tile </li></ul><ul><li>Compare color of each pixel in the master photo and get the photo tile with the average color that matches the pixel best </li></ul><ul><li>Form the mosaic with that photo tile </li></ul>
  8. 8. Reduce the image
  9. 9. Notes <ul><li>You don’t want a large master photo – each pixel in the master photo will be replaced by a photo tile </li></ul><ul><li>For example, if you have a 640 x 480 photo, you will need to process and replace 307,200 pixels with photos! </li></ul><ul><li>A fair number is 100 x 75 (which is the same ratio as 640 x 480) but only has 7,500 pixels. </li></ul>
  10. 10. Y!BOSS to grab images
  11. 11. Notes <ul><li>Population is the number of photo tiles to take from the image search. </li></ul><ul><li>Step count is the number of images requested from BOSS per query. </li></ul><ul><li>photo_tiles is the array of photo URLs </li></ul>
  12. 12. Get average color of each photo tile
  13. 13. Notes <ul><li>The RGB color model is an additive color model in which R ed, G reen, and B lue light are added together in various ways to produce different colors. </li></ul><ul><li>What we need to determine is the RGB representation of the average color of the photo tile </li></ul><ul><li>To do this, we examine the color of each pixel in the tile, add up all the reds and divide it by the total number of pixels to find the red of that average color and do the same for green and blue. </li></ul>
  14. 14. Get best fitting color for each pixel
  15. 15. Get best fitting color for each pixel
  16. 16. Notes <ul><li>We need to find the difference between one color and another. (also called delta E) </li></ul><ul><li>To simplify matters we determine the difference or distance between two colors by calculating the (Euclidean) distance between two points. </li></ul><ul><li>In the case of a color, we treat it as a 3-dimensional coordinate but instead of x, y, an z we use R, G, and B. </li></ul>
  17. 17. Create mosaic!
  18. 18. Notes <ul><li>The larger the tile size is, the clearer and more vivid the photo tile is </li></ul><ul><li>However this also means the final mosaic file will be bigger and it will take longer to process, so we need to balance the needs </li></ul>
  19. 22. Final slide <ul><li>A very simple bare-bones Ruby program to churn out mosaics </li></ul><ul><li>Mosaics created repeat the usage of certain tiles </li></ul><ul><li>Not very fast but relatively good results! </li></ul><ul><li> </li></ul>