我编写了一个程序,它接收由我的另一个程序规范化的图像输入。你知道吗
输入图像为:
程序输出图像的标准化版本。规范化方法在下面进一步显示。你知道吗
输出错误地包含在像素的多色马赛克中。给定上述输入,输出为(缩放):
预期结果应为上述平面。你知道吗
在以下代码中:
__plot_images_predicted_for_testing
用Matplotlib.Pyplot文件从RAM输入图像中包含输出图像的窗口__fetch_the_normalized_image
获取输入图像,__load_XYZ
将输入图像从磁盘加载到RAM。你知道吗import numpy as np
from numpy import array
import matplotlib.pyplot as plt
import os
from skimage import data
class Launcher:
__PATH_CONTAINING_THE_NORMALIZED_IMAGE = "/content/drive/My Drive/Informatique/Projets_Informatiques" \
"/Projets_Python/bug_isolation_mosaics_of_pixels/normalized_image"
__PATH_CONTAINING_THE_DENORMALIZED_IMAGE = "/content/drive/My Drive/Informatique/Projets_Informatiques" \
"/Projets_Python/bug_isolation_mosaics_of_pixels" \
"/denormalized_image"
def __init__(self):
pass
def show_denormalized_image_from_normalized_image(self):
self.__plot_images_predicted_for_testing()
def __plot_images_predicted_for_testing(self):
normalized_images = self.__fetch_the_normalized_image()
normalized_image = normalized_images[[0, 0, 0]]
denormalized_image = self.__denormalize(normalized_image)
figure = plt.figure(figsize=(15, 5))
plt.subplot(1, 3, 1)
plt.imshow(denormalized_image[1], interpolation='nearest')
plt.axis('off')
plt.tight_layout()
plt.savefig(self.__PATH_CONTAINING_THE_DENORMALIZED_IMAGE + '/the_denormalized_image')
plt.close(figure)
@staticmethod
def __denormalize(input_data):
input_data = (input_data + 1) * 127.5
return input_data.astype(np.uint8)
def __fetch_the_normalized_image(self):
print("Loading the normalized image")
images = []
loaded_images = self.__load_data(
Launcher.__PATH_CONTAINING_THE_NORMALIZED_IMAGE,
".jpg")
for img in range(len(loaded_images)):
images.append(loaded_images[img])
images = array(images)
print("/Loading the normalized image")
return images
@staticmethod
def __load_data_from_dirs(dirs, ext):
files = []
file_names = []
count = 0
for d in dirs:
for f in os.listdir(d):
if f.endswith(ext):
image = data.imread(os.path.join(d, f))
if len(image.shape) > 2:
files.append(image)
file_names.append(os.path.join(d, f))
count = count + 1
return files
def __load_path(self, path):
directories = []
if os.path.isdir(path):
directories.append(path)
for elem in os.listdir(path):
if os.path.isdir(os.path.join(path, elem)):
directories = directories + self.__load_path(os.path.join(path, elem))
directories.append(os.path.join(path, elem))
return directories
def __load_data(self, directory, ext):
files = self.__load_data_from_dirs(self.__load_path(directory), ext)
return files
print("Executing the program")
launcher = Launcher()
launcher.show_denormalized_image_from_normalized_image()
print("/Executing the program")
你知道我为什么用这种非规范化方法得到一个多色的像素马赛克吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐