Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用递归插值法计算平滑彩色地图_Python_Image_Python 3.x_Image Processing_Recursion - Fatal编程技术网

Python 用递归插值法计算平滑彩色地图

Python 用递归插值法计算平滑彩色地图,python,image,python-3.x,image-processing,recursion,Python,Image,Python 3.x,Image Processing,Recursion,我正在递归计算mandelbrot集,并尝试使用平滑着色算法执行线性插值。但是,这会返回浮点RGB值,我无法将其放入正在使用的ppm图像中,因此我必须使用int(),对其进行取整,从而创建一个更平滑但仍然带状的图像 有没有更简单的方法可以产生更好的非带状图像 第二个函数是一个非常糟糕的hack,它只是在玩弄一些想法,因为平滑算法似乎在生成256**3范围内的rgb值 注释掉了我正在做的线性插值 以下是我的三项职能: def linear_interp(self, color_1, color

我正在递归计算mandelbrot集,并尝试使用平滑着色算法执行线性插值。但是,这会返回浮点RGB值,我无法将其放入正在使用的ppm图像中,因此我必须使用
int()
,对其进行取整,从而创建一个更平滑但仍然带状的图像

有没有更简单的方法可以产生更好的非带状图像

第二个函数是一个非常糟糕的hack,它只是在玩弄一些想法,因为平滑算法似乎在生成256**3范围内的rgb值

注释掉了我正在做的线性插值

以下是我的三项职能:

  def linear_interp(self, color_1, color_2, i):
    r = (color_1[0] * (1 - i)) + (color_2[0] * i)
    g = (color_1[1] * (1 - i)) + (color_2[1] * i)
    b = (color_1[2] * (1 - i)) + (color_2[2] * i)

    return (int(abs(r)), int(abs(g)), int(abs(b)))

  def mandel(self, x, y, z, iteration = 0):
    mod_z = sqrt((z.real * z.real) + (z.imag * z.imag))
    #If its not in the set or we have reached the maximum depth
    if  abs(z) >= 2.00 or iteration == DEPTH:
        if iteration == DEPTH:
            mu = iteration
        else:
            mu = iteration + 1 - log(log(mod_z)) / log(2)

    else:
        mu = 0
        z = (z * z) + self.c
        self.mandel(x, y, z, iteration + 1)
    return mu

 def create_image(self):
    begin = time.time() #For computing how long it took (start time)
    self.rgb.palette = []
    for y in range(HEIGHT):
        self.rgb.palette.append([]) #Need to create the rows of our ppm
        for x in range(WIDTH):
            self.c =  complex(x * ((self.max_a - self.min_a) / WIDTH) + self.min_a, 
                              y * ((self.max_b - self.min_b) / HEIGHT) + self.min_b)

            z = self.c

            q = (self.c.real - 0.25)**2 + (self.c.imag * self.c.imag)
            x = self.c.real
            y2 = self.c.imag * self.c.imag

            if not (q*(q + (x - 0.25)) < y2 / 4.0 or (x + 1.0)**2 + y2 <0.0625): 
                mu = self.mandel(x, y, z, iteration = 0)
                rgb = self.linear_interp((255, 255, 0), (55, 55, 0), mu)
                self.rgb.palette[y].append(rgb)
            else:
                self.rgb.palette[y].append((55, 55, 0))
            if self.progress_bar != None:
                self.progress_bar["value"] = y
                self.canvas.update()
def-linear\u-interp(self、color\u 1、color\u 2、i):
r=(颜色_1[0]*(1-i))+(颜色_2[0]*i)
g=(颜色_1[1]*(1-i))+(颜色_2[1]*i)
b=(颜色_1[2]*(1-i))+(颜色_2[2]*i)
返回(int(abs(r)),int(abs(g)),int(abs(b)))
def mandel(self,x,y,z,迭代=0):
mod_z=sqrt((z.real*z.real)+(z.imag*z.imag))
#如果它不在集合中,或者我们已经达到最大深度
如果abs(z)>=2.00或迭代==深度:
如果迭代=深度:
mu=迭代
其他:
mu=迭代+1-log(log(mod_z))/log(2)
其他:
μ=0
z=(z*z)+self.c
self.mandel(x,y,z,迭代+1)
还亩
def创建_映像(自):
begin=time.time()#用于计算花费的时间(开始时间)
self.rgb.palete=[]
对于范围内的y(高度):
self.rgb.palete.append([])#需要创建ppm的行
对于范围内的x(宽度):
self.c=复数(x*((self.max\u a-self.min\u a)/宽度)+self.min\u a,
y*((自最大值-自最小值)/高度)+自最小值)
z=自我。c
q=(self.c.real-0.25)**2+(self.c.imag*self.c.imag)
x=自循环真实值
y2=自c.imag*自c.imag

如果不是(q*(q+(x-0.25))
else:
    mu = 0
    self.mandel(x, y, z, iteration + 1)
return mu
这并没有正确地从递归调用中传递
mu
的值,因此在一次调用后,如果没有达到最低点,则会导致黑色。请尝试

else:
    ...
    mu = self.mandel(x, y, z, iteration + 1)
return mu

你真的需要把它简化为一个最小的例子。你的输出图像中的色带有多糟糕?我倾向于说,如果你停留在固定的像素数上,而只有整数颜色,那么你就不能做得更好了。@Overflow2341313我想现在你已经到了你必须处理的像素密度的极限了。