0

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.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Perfectoid
  • 15
  • 2

1 Answers1

0

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

MegaKarg
  • 110
  • 1
  • 7
  • Thanks for the reply but how do I call the images(first_image and second_image) because all images are the same just different forms. do i create another function or what? – Perfectoid Apr 18 '22 at 03:24
  • I have issues importing the library to test it but all you need to do is return the images instead of displaying them. From each of the transformation functions return the transformed image. Save them all in variables and then concatenate using np.concatenate. Then you can display them all in one window. – MegaKarg Apr 18 '22 at 03:49
  • that actually uses **`numpy`** for the arrangement, not OpenCV. – Christoph Rackwitz Apr 18 '22 at 12:48