-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageProcessing.java
58 lines (52 loc) · 1.05 KB
/
ImageProcessing.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.*;
import java.io.*;
/**
* Kattis problem imageprocessing
*
* Difficulty: 2.3
* Solved: 2018-01-23
*/
public class ImageProcessing {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int h0,w0,n,m;
int h1,w1;
h0 = sc.nextInt();
w0 = sc.nextInt();
n = sc.nextInt();
m = sc.nextInt();
h1 = h0-n+1;
w1 = w0-m+1;
int[][] original = new int[h0][w0];
int[][] kernel = new int[n][m];
int[][] changed = new int[h1][w1];
for(int i=0;i<h0;i++){
for(int j=0;j<w0;j++){
original[i][j]=sc.nextInt();
}
}
for(int i=n-1;i>=0;i--){
for(int j=m-1;j>=0;j--){
kernel[i][j]=sc.nextInt();
}
}
for(int i=0;i<h1;i++){
for(int j=0;j<w1;j++){
int accum=0;
for(int ii=0;ii<n;ii++){
for(int jj=0;jj<m;jj++){
accum+=kernel[ii][jj]*original[i+ii][j+jj];
}
}
changed[i][j]=accum;
}
}
for(int i=0;i<h1;i++){
for(int j=0;j<w1;j++){
System.out.print(changed[i][j]);
System.out.print(' ');
}
System.out.println();
}
}
}