我想放大图片的一部分,在这个例子中,是鼻子。
我有一个函数来选择要放大的部分。
def copyAndPaste(picture):
height = getHeight(picture)
width = getWidth(picture)
newPicture = makeEmptyPicture(width, height)
for x in range(width):
for y in range(height):
pxl = getPixel(picture,x,y)
if (x>48 and x<59) and (y>58 and y<71):
newPxl =getPixel(newPicture, #?,#?)
else:
newPxl = getPixel(newPicture, x,y)
color = getColor(pxl)
setColor(newPxl,color)
return newPicture
def d():
f=pickAFile()
picture=makePicture(f)
newPicture = copyAndPaste(picture)
writePictureTo(newPicture, r"D:\FOLDER\0Pic4.jpg")
explore (newPicture)
我还有一个放大图片的功能:
def Enlarge(picture):
height = getHeight(picture)
width = getWidth(picture)
newPicture = makeEmptyPicture(width*2, height*2)
x1=0
for x in range(0,width):
y1=0
for y in range(0,height):
pxl = getPixel(picture,x,y)
newPxl = getPixel(newPicture, x1,y1)
color = getColor(pxl)
setColor(newPxl,color)
y1=y1+2
x1=x1+2
return newPicture
例如
发件人:
致:
我试过很多方法,但都不知道如何把这两种方法结合起来放大一张照片的一部分,而把剩下的部分保留下来。
这就是最终的图片应该看起来的样子(尽管它很可笑)
我一直在练习小图片,因为程序执行起来可能要花很长时间,用大图片是不可行的,在这个阶段,意味着结果是粗略的,但至少会显示它是否有效。
我仍然不确定我是否理解你想做的,但我认为是这样的:你想复制粘贴鼻子,而不是剪切粘贴,你想把粘贴好的复制品以和你的第二个例子一样的方式翻倍。
所以,在脸中间会有一个10x10的鼻子,再加上一个20x20洗出来的鼻子在右下方。
首先,要复制和粘贴,只需将像素复制到新旧位置,而不是仅复制到新位置:
现在,要放大新粘贴的副本,只需将偏移量加倍即可。换句话说,49,59处的第一个像素转到149159,但50,60处的像素转到151161,51,61处的像素转到153163,依此类推。
所以,你想要的是得到49,59之间的距离,加倍,再加回到49,59,然后移动100100:
这只是为了记录和娱乐,不是答案。。。
但是正如前面提到的,
abarnert
("Are you sure they just want you to leave 3 white pixels for every copied pixel, rather than copying the same pixel 4 times?"
),作为一个缩放算法,这是非常荒谬的。。。更有趣但更基本的缩放图像的方法是^{} 。
………
………
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
其他有趣的算法here。
这里是
Eagle Algorithm
的一个基本实现(可以很好地处理具有少量不同颜色的图像):原件:
最近的邻居:
鹰:
享受吧!
相关问题 更多 >
编程相关推荐