编程介的小学生 2017-04-18 11:35 采纳率: 20.5%
浏览 699
已采纳

Filtering

Median filtering is a common method in image processing. It is particularly useful to reduce speckle noise and pepper noise. Its edge-preserving nature makes it useful in cases where edge blurring is undesirable.

Median filtering is defined as follow. Let X be the matrix represents an image, and the matrix's size is p * q. The coordinate of the matrix's top left element is (1, 1). The result of the median filtering with an m * n (where m, n are both odd integers) rectangle window is also a matrix Y. The window scan the image from left to right and from top to bottom. We defined the new matrix as follow:

For each (i, j) where 1 <= i <= n and 1 <= j <= m,

when (m + 1) / 2 <= i <= p - (m - 1) / 2 and (n + 1) / 2 <= j <= q - (n - 1) / 2, consider the windows whose center is at (i, j)). Y(i, j) = the median number (rank the middle) among the numbers that the window covers.

In other cases, Y(i, j) = X(i, j)
For example, if the window's size is 3 * 3 and the matrix X is:

1 2 3 3 2
1 4 2 3 3
2 5 6 2 3
3 2 1 4 2
3 3 2 7 1
4 5 6 7 8
1 1 2 3 4
then the new matrix Y will be:

1 2 3 3 2
1 2 3 3 3
2 2 3 3 3
3 3 3 2 2
3 3 4 4 1
4 3 3 4 8
1 1 2 3 4
Now you are given the matrix X, and your task is to calculate the matrix Y.

Input

There are multicases.

In the first line, there are two numbers p and q (1 <= p, q <= 500), which indicate the size of matrix X. Follow p lines, and each line has q integers, which are all in range [0, 255].

There are two integers m, n (1 <= m, n <= 49, p >= m, q >= n, and m, n are odd integers. ) in the last line, which indicate the window's size.

There is a line between cases.

Output

You should output the matrix Y. Print a line after each case.

Sample Input

5 5
1 2 3 3 2
1 4 2 3 3
2 5 6 2 3
3 2 1 4 2
3 3 2 7 1
3 3

7 5
1 2 3 3 2
1 4 2 3 3
2 5 6 2 3
3 2 1 4 2
3 3 2 7 1
4 5 6 7 8
1 1 2 3 4
3 3
Sample Output

1 2 3 3 2
1 2 3 3 3
2 2 3 3 3
3 3 3 2 2
3 3 2 7 1

1 2 3 3 2
1 2 3 3 3
2 2 3 3 3
3 3 3 2 2
3 3 4 4 1
4 3 3 4 8
1 1 2 3 4

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-03 15:53
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)