4 kyu

Challenge Fun #20: Edge Detection

28 of 49myjinxin2015

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:

image

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] string image

A RLE string of image.

  • [output] a string

A RLE string calculate by using the edge detection algorithm.

Algorithms

Stats:

CreatedMar 8, 2017
PublishedMar 8, 2017
Warriors Trained791
Total Skips141
Total Code Submissions642
Total Times Completed49
JavaScript Completions28
Ruby Completions6
Python Completions22
Total Stars63
% of votes with a positive feedback rating94% of 17
Total "Very Satisfied" Votes15
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
4 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • ZED.CWT Avatar
  • user8436785 Avatar
  • Hippunky Avatar
  • dfhwze Avatar
  • 4500zenja1 Avatar
Ad