如何水平放置所有三个图像?

发布于 2025-01-22 09:59:40 字数 1852 浏览 1 评论 0原文

我的功能可以将原始图像更改为灰度,负面图像和颜色黄色为蓝色。该代码应该在3个不同的窗口中运行并显示图像。我该如何水平将它们全部放置? 这是代码。

PS我不会使用PIL。

from cImage import *

#there is a code here that that defines the functions, i've cut it out from my 
question

def generalTransform(imageFile):
    myimagewindow = ImageWin("Image Processing",300,200)
    oldimage = FileImage(imageFile)
    oldimage.draw(myimagewindow)

    newimage = pixelMapper(oldimage,changeYellowToBlue)       
    newimage.setPosition(oldimage.getWidth()+1,0)
    newimage.draw(myimagewindow)
    myimagewindow.exitOnClick()
def main():
    generalTransform("mickey.gif")

main()
def makenegative(imageFile):
    oldImage=FileImage(imageFile)
    width=oldImage.getWidth()
    height=oldImage.getHeight()
    myImageWindow=ImageWin('negativeimage', width*2, height)
    oldImage.draw(myImageWindow)
    newIm=EmptyImage(width, height)
    for row in range(height):
        for col in range(width):
            oldPixel=oldImage.getPixel(col, row)
            newPixel=negativePixel(oldPixel)
            newIm.setPixel(col, row, newPixel)
    newIm.setPosition(width+1, 0)
    newIm.draw(myImageWindow)
    myImageWindow.exitOnClick()
def main():
    makenegative("mickey.gif")

main()
def makeGrayscale(imageFile):
    oldImage=FileImage(imageFile)
    width=oldImage.getWidth()
    height=oldImage.getHeight()
    myImageWindow=ImageWin('grayimage', width*2, height)
    oldImage.draw(myImageWindow)
    newIm=EmptyImage(width, height)
    for row in range(height):
        for col in range(width):
            oldPixel=oldImage.getPixel(col, row)
            newPixel=grayPixel(oldPixel)
            newIm.setPixel(col, row, newPixel)
    newIm.setPosition(width+1, 0)
    newIm.draw(myImageWindow)
    myImageWindow.exitOnClick()
def main():
    makeGrayscale("mickey.gif")

main()

这是代码的一部分。

I have a function that changes the original image to gray scale, negative image and the color yellow to blue. The code is supposed to run and show the images in 3 different windows. How can I put them all in one, horizontally?
here is the code.

p.s I won't be using PIL.

from cImage import *

#there is a code here that that defines the functions, i've cut it out from my 
question

def generalTransform(imageFile):
    myimagewindow = ImageWin("Image Processing",300,200)
    oldimage = FileImage(imageFile)
    oldimage.draw(myimagewindow)

    newimage = pixelMapper(oldimage,changeYellowToBlue)       
    newimage.setPosition(oldimage.getWidth()+1,0)
    newimage.draw(myimagewindow)
    myimagewindow.exitOnClick()
def main():
    generalTransform("mickey.gif")

main()
def makenegative(imageFile):
    oldImage=FileImage(imageFile)
    width=oldImage.getWidth()
    height=oldImage.getHeight()
    myImageWindow=ImageWin('negativeimage', width*2, height)
    oldImage.draw(myImageWindow)
    newIm=EmptyImage(width, height)
    for row in range(height):
        for col in range(width):
            oldPixel=oldImage.getPixel(col, row)
            newPixel=negativePixel(oldPixel)
            newIm.setPixel(col, row, newPixel)
    newIm.setPosition(width+1, 0)
    newIm.draw(myImageWindow)
    myImageWindow.exitOnClick()
def main():
    makenegative("mickey.gif")

main()
def makeGrayscale(imageFile):
    oldImage=FileImage(imageFile)
    width=oldImage.getWidth()
    height=oldImage.getHeight()
    myImageWindow=ImageWin('grayimage', width*2, height)
    oldImage.draw(myImageWindow)
    newIm=EmptyImage(width, height)
    for row in range(height):
        for col in range(width):
            oldPixel=oldImage.getPixel(col, row)
            newPixel=grayPixel(oldPixel)
            newIm.setPixel(col, row, newPixel)
    newIm.setPosition(width+1, 0)
    newIm.draw(myImageWindow)
    myImageWindow.exitOnClick()
def main():
    makeGrayscale("mickey.gif")

main()

This is part of the code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

反话 2025-01-29 09:59:40

为此使用OpenCV库怎么样?
将图像转到灰度之后,您可以将它们连接到水平轴上并彼此相邻显示。

import cv2
import numpy as np

first_image = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
second_image = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
# other transformations that you want

# concatenating images horizontally
horizontal_concat = np.concatenate((first_image, second_image), axis=1)
cv2.imshow(horizontal_concat)

cv2.waitKey()
cv2.destroyAllWindows()

干杯

how about using the OpenCV library for this?
After turning the images to grayscale you can concatenate them on the horizontal axis and display them next to each other.

import cv2
import numpy as np

first_image = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
second_image = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
# other transformations that you want

# concatenating images horizontally
horizontal_concat = np.concatenate((first_image, second_image), axis=1)
cv2.imshow(horizontal_concat)

cv2.waitKey()
cv2.destroyAllWindows()

Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文