UOMOP
def Restore_Image(input, c_or_g) 본문
def Restore_Image(input, c_or_g):
# print("input's len : {}".format(len(input)))
if c_or_g == "color":
one_step = int(len(input) / 3)
channel_1 = input[0:one_step]
channel_2 = input[one_step:2 * one_step]
channel_3 = input[2 * one_step:len(input)]
print("ch_1 len : {}".format(len(channel_1)))
print("ch_2 len : {}".format(len(channel_2)))
print("ch_3 len : {}".format(len(channel_3)))
str_1 = list()
str_2 = list()
str_3 = list()
for i in range(len(channel_1)):
str_1.append(str(channel_1[i]))
str_2.append(str(channel_2[i]))
str_3.append(str(channel_3[i]))
print("str_1's len : {}".format(len(str_1)))
print("str_2's len : {}".format(len(str_2)))
print("str_3's len : {}".format(len(str_3)))
pixel_1 = list()
pixel_2 = list()
pixel_3 = list()
for i in range(int(len(channel_1) / 8)):
pixel_1.append(int(''.join(str_1[8 * i:8 * (i + 1)]), 2))
pixel_2.append(int(''.join(str_2[8 * i:8 * (i + 1)]), 2))
pixel_3.append(int(''.join(str_3[8 * i:8 * (i + 1)]), 2))
print("pixel_1's len : {}".format(len(pixel_1)))
print("pixel_2's len : {}".format(len(pixel_2)))
print("pixel_3's len : {}".format(len(pixel_3)))
array_1 = np.reshape((np.array(pixel_1, dtype=np.uint8)), (int(sqrt(len(pixel_1))), -1))
array_2 = np.reshape((np.array(pixel_2, dtype=np.uint8)), (int(sqrt(len(pixel_1))), -1))
array_3 = np.reshape((np.array(pixel_3, dtype=np.uint8)), (int(sqrt(len(pixel_1))), -1))
print("array_1's shape : {}".format(array_1.shape))
print("array_2's shape : {}".format(array_2.shape))
print("array_3's shape : {}".format(array_3.shape))
print()
print("array_1 : {}".format(array_1))
print("array_2 : {}".format(array_2))
print("array_3 : {}".format(array_3))
array = np.array([array_1, array_2, array_3])
############################ flattend bit stream을 어떻게 3channel image info.로 바꿀 것인지 짜보기
print("array's shape : {}".format(array.shape))
print()
print()
print(array)
elif c_or_g == "gray":
channel = input
str_1 = list()
for i in range(len(channel)):
str_1.append(str(channel[i]))
pixel_1 = list()
for i in range(int(len(channel) / 8)):
pixel_1.append(int(''.join(str_1[8 * i:8 * (i + 1)]), 2))
array = np.reshape((np.array(pixel_1, dtype=np.uint8)), (int(sqrt(len(pixel_1))), -1))
return array
'Wireless Comm. > Python' 카테고리의 다른 글
LPDC (n, k) comparison (0) | 2023.05.03 |
---|---|
save2 (0) | 2023.05.03 |
save1 (0) | 2023.05.02 |
16/64QAM (0) | 2023.05.02 |
Linear Block Coding Comparison (6, 3) vs (7, 4) (0) | 2023.05.02 |
Comments