Challenge Fun #20: Edge Detection
Description:
Task
IONU Satellite Imaging, Inc. records and stores very large images using run length encoding. You are to write a program that reads a compressed image, finds the edges in the image, as described below, and outputs another compressed image of the detected edges.
A simple edge detection algorithm sets an output pixel's value to be the maximum absolute value of the differences between it and all its surrounding pixels in the input image. Consider the input image below:
The upper left pixel in the output image is the maximum of the values |15-15|,|15-100|, and |15-100|, which is 85. The pixel in the 4th row, 2nd column is computed as the maximum of |175-100|, |175-100|, |175-100|, |175-175|, |175-25|, |175-175|,|175-175|, and |175-25|, which is 150.
Images contain 2 to 1,000,000,000 (10^9) pixels. All images are encoded using run length encoding (RLE). This is a sequence of pairs, containing pixel value (0-255) and run length (1-10^9). Input images have at most 1,000 of these pairs. Successive pairs have different pixel values. All lines in an image contain the same number of pixels.
For the iamge as the example above, the RLE encoding string is "7 15 4 100 15 25 2 175 2 25 5 175 2 25 5"
Each image starts with the width, in pixels(means the first number 7)
This is followed by the RLE pairs(two number is a pair).
7 ----> image width
15 4 ----> a pair(color value + number of pixel)
100 15 ...........ALL.......................
25 2 ..........THESE......................
175 2 ...........ARE.......................
25 5 ..........PAIRS......................
175 2 ...........LIKE......................
25 5 ..........ABOVE......................
Your task is to calculate the result by using the edge detection algorithm above. Returns a encoding string in the same format as the input string.
Exaple
Please see examples in the example test block.
Input/Output
[input]
stringimage
A RLE string of image.
[output]
a string
A RLE string calculate by using the edge detection algorithm.
Similar Kata:
Stats:
Created | Mar 8, 2017 |
Published | Mar 8, 2017 |
Warriors Trained | 791 |
Total Skips | 141 |
Total Code Submissions | 642 |
Total Times Completed | 49 |
JavaScript Completions | 28 |
Ruby Completions | 6 |
Python Completions | 22 |
Total Stars | 63 |
% of votes with a positive feedback rating | 94% of 17 |
Total "Very Satisfied" Votes | 15 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 3 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 5 kyu |