How do I put all three images horizontally?

647 Views Asked by At

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.

1

There are 1 best solutions below

3
On

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