当前位置:网站首页>PTA 1066 image filtering (15 points)

PTA 1066 image filtering (15 points)

2022-06-24 05:10:00 freesan44

subject

Image filtering is to dye the unimportant pixels in the image into the background color , Make important parts stand out . Now give a black-and-white image , You are required to replace all pixel colors with a specified color when the gray value is within a specified range .

Input format :

Input gives the resolution of an image on the first line , That is, two positive integers M and N(0<M,N≤500), The other is the end point of the gray value interval to be filtered A and B(0≤A<B≤255)、 And the specified replacement gray value . And then M That's ok , Each line gives N The gray value of a pixel , Separated by spaces . All gray values are in 0, 255 Within the interval .

Output format :

Output the filtered image as required . The output M That's ok , Each row N Pixel gray value , Percentage of each gray value 3 position ( For example, black should be displayed as 000), Separated by a space . There must be no extra space at the beginning and end of the line .

 sample input :
3 5 100 150 0
3 189 254 101 119
150 233 151 99 100
88 123 149 0 255
 No blank lines at the end 
 sample output :
003 189 254 000 000
000 233 151 099 000
088 000 000 000 255
 No blank lines at the end 

Their thinking

M,N,A,B,H = map(int,input().split())
# M,N,A,B,H = map(int, "3 5 100 150 0".split(" "))
zongResList = []
for i in range(M):
    for j in input().split():
        if A <= int(j) <= B:
            zongResList.append("%03d" % H)
        else:
            zongResList.append("%03d" % j)
    # The following methods failed in the final case 
    # #  The input is converted to int Of List
    # inputList = list(map(int, input().split()))
    # # inputList = list(map(int, "3 189 254 101 119".split()))
    # resList = []
    # for j in inputList:
    #     res = None
    #     if A <= int(j) <= B:
    #         #  Make up 0 escape 
    #         # res = "{:0>3d}".format(int(H))
    #         res = "%03d" % H
    #     else:
    #         #  Make up 0 escape 
    #         # res = "{:0>3d}".format(int(j))
    #         res = "%03d" % j
    #     # resList.append(res)
    #     zongResList.append(res)
    # # zongResList.append(resList)
    # # print(" ".join(resList))
for i in range(0, len(zongResList),N):
    print(' '.join(zongResList[i:i+N]))
原网站

版权声明
本文为[freesan44]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/08/20210822001429517a.html