Skip to content
rock2zPublic

About

An algorithm used to draw the skyline from an existing image.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Skyline Extraction

An algorithm used to draw the skyline from an existing image.

The goal is to achieve an effect similar to this (image found online, please contact me regarding copyright issues):
Skyline Example


Steps to Extract the Skyline

  1. Read the image and extract the RGB values into an array.
  2. Extract the blue channel values and plot a histogram.
  3. Determine the threshold based on the histogram.
  4. Classify pixels:
    • Blue channel values above the threshold are painted white (sky).
    • Blue channel values below the threshold are painted black (land).
  5. Traverse the image from top to bottom and keep the first black point for each column. This forms a preliminary skyline.
  6. Connect discontinuous points in the skyline to form a complete curve.

Detailed Explanation

Each pixel has an RGB value, e.g., (10, 124, 255). The third value (255) is the blue channel, which ranges from 0 to 255.

  • By analyzing the blue channel values of all pixels, we can create a histogram.
  • This histogram will likely show two peaks:
    • One peak represents the sky (high blue values).
    • The other represents the land (lower blue values).
  • The minimum value between the two peaks is used as the threshold.

After applying the threshold, the image looks like this:
Classified Image


Key Points

1. Threshold Calculation (Step 3)

  • Identify the two peaks in the histogram.
  • The minimum value between these peaks is the threshold.
  • If this step is skipped, the threshold may be set outside the peaks, leading to inaccurate results.

2. Connecting Discontinuous Points (Step 6)

At this stage, the preliminary skyline might look like this:
Disconnected Skyline

  • Some x-coordinates appear to have no black points, but they do exist at unusual positions.
  • These invalid points are ignored.
  • The remaining valid points form a discrete point graph.
  • To connect the points:
    • Start from a point.
    • Greedily search the surrounding 8 points to find the shortest distance to the next point.
    • Connect all points sequentially to form a continuous skyline.

Final Thoughts

And that’s it!

About

An algorithm used to draw the skyline from an existing image.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages