Python e le immagini di output - PullRequest
       22

Python e le immagini di output

0 голосов
/ 08 апреля 2020

У меня есть код для запуска в python. Этот код возвращает изображение как результат, но это изображение не визуализируется на p c. Предупреждающее сообщение говорит мне "xxx.png". Файл был перемещен или переименован. Что это значит? Я должен изменить каталог изображений? Я не знаю, как кодировать это в python. Спасибо за помощь.

Это код:

# Python code for Mandelbrot Fractal 

# Import necessary libraries 
from PIL import Image 
from numpy import complex, array 
import colorsys 

# setting the width of the output image as 1024 
WIDTH = 1024

# a function to return a tuple of colors 
# as integer value of rgb 
def rgb_conv(i): 
    color = 255 * array(colorsys.hsv_to_rgb(i / 255.0, 1.0, 0.5)) 
    return tuple(color.astype(int)) 

# function defining a mandelbrot 
def mandelbrot(x, y): 
    c0 = complex(x, y) 
    c = 0
    for i in range(1, 1000): 
        if abs(c) > 2: 
            return rgb_conv(i) 
        c = c * c + c0 
    return (0, 0, 0) 

# creating the new image in RGB mode 
img = Image.new('RGB', (WIDTH, int(WIDTH / 2))) 
pixels = img.load() 

for x in range(img.size[0]): 

    # displaying the progress as percentage 
    print("%.2f %%" % (x / WIDTH * 100.0)) 
    for y in range(img.size[1]): 
        pixels[x, y] = mandelbrot((x - (0.75 * WIDTH)) / (WIDTH / 4), 
                                    (y - (WIDTH / 4)) / (WIDTH / 4)) 

# to display the created fractal after 
# completing the given number of iterations 
img.show() 
...