8000 Create Box Blur.md · RAravindDS/CodeSignal_Answers@fbc6101 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8000 fbc6101

Browse files
authored
Create Box Blur.md
1 parent 630b9c2 commit fbc6101

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Arcade/Box Blur.md

+48
8541
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
## Question
3+
Last night you partied a little too hard. Now there's a black and white photo of you that's about to go viral! You can't let this ruin your reputation, so you want to apply the box blur algorithm to the photo to hide its content.
4+
5+
The pixels in the input image are represented as integers. The algorithm distorts the input image in the following way: Every pixel x in the output image has a value equal to the average value of the pixel values from the 3 × 3 square that has its center at x, including x itself. All the pixels on the border of x are then removed.
6+
Return the blurred image as an integer, with the fractions rounded down.
7+
8+
Example
9+
10+
For
11+
```python
12+
image = [[1, 1, 1],
13+
[1, 7, 1],
14+
[1, 1, 1]]
15+
```
16+
the output should be solution(image) = [[1]].
17+
18+
## Answer:
19+
20+
```python
21+
import numpy as np
22+
23+
24+
def solution(a):
25+
26+
bro = np.array(a)
27+
28+
brs = []
29+
count = 0
30+
outer_count = 0
31+
second_loop = 0
32+
33+
for i in range(len(a)-2):
34+
intermediate_list = []
35+
36+
for bros in range(len(a[0])-2):
37+
intermediate_list.append(int(bro[outer_count:3+second_loop, count:3+count].mean()))
38+
count += 1
39+
40+
brs.append(intermediate_list)
41+
second_loop += 1
42+
outer_count += 1
43+
count = 0
44+
45+
return brs
46+
```
47+
48+
**Give a star ✨**

0 commit comments

Comments
 (0)
0