I was assigned to optimize the HPF using C++. Fyi, the original image is 512x512.
By getting the .dat file that is produced by using Python script, I applied a 5x5 HPF on it with 2 zero-pad with stride = 1 so the result image is still in 512x512. By using the custom algorithm, the HPF result is shown in the Manual HPF result. Since it is different with the result as shown in High Pass Filter for image processing in python by using scipy/numpy , may I know is this Manual HPF result acceptable?
The *.dat file is a list of number as shown below
646
964
-475
.
.
.
.
.
-481
481
Then, the Python script (as shown below) is used to convert the list of number into the 2D array. Then this 2D array is converted into 512*512 greyscale image.
from PIL import Image
import numpy as np
file = "ans.dat"
pixel = []
convertedPixel = []
z = 0
arr = np.zeros((512,512))
with open(file) as data_file:
for line in data_file:
line_list = line.replace(' ',',')
line_list = line_list.replace(',\n','')
pixel.append(int(line_list))
pixel.append(int(line_list))
pixel.append(int(line_list))
array = np.array(pixel)
for i in array:
if i > 255:
i = 255
if i < 0:
i = 0
array = np.uint8(array)
array = array.reshape(512,512,3)
print(array)
'''
f = open('check.dat', 'w')
for i in range (0, len(array)):
f.write(str(array[i])+"\n")
f.close()
'''
#new_image = Image.fromarray(array)
#new_image = new_image.convert("RGB")
#new_image.save('new.png')