3

I want to display original image left side and grayscale image on right side. Below is my code, I create grayscale image and create window, but I couldn't put grayscale image to right side. How can I do this?

import cv
import time
from PIL import Image
import sys

filePath = raw_input("file path: ")
filename = filePath

img = cv.LoadImage(filename)
imgGrayScale = cv.LoadImage(filename, cv.CV_LOAD_IMAGE_GRAYSCALE) # create grayscale image

imgW = img.width
imgH = img.height

cv.NamedWindow("title", cv.CV_WINDOW_AUTOSIZE)
cv.ShowImage("title", img )
cv.ResizeWindow("title", imgW * 2, imgH)

cv.WaitKey()
2

2 Answers 2

9

First concatenate the images either horizontally (across columns) or vertically (across rows) and then display it as a single image.

import numpy as np
import cv2
from skimage.data import astronaut
img=cv2.cvtColor(astronaut(),cv2.COLOR_BGR2RGB)
numpy_horizontal_concat = np.concatenate((img, img), axis=1)
cv2.imshow('Numpy Horizontal Concat', numpy_horizontal_concat)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

As far as I know, one window, one image. So create a new image with imgW*2 and copy the contents of the grayscale image at the region starting from (originalimage.width,0). The ROI capabilities may be helpful to you.

2 Comments

I found this one: DisplayManyImages I couldn't for python
aww, that's damn old. but basically the same idea as the answer above, make an image with space for both, and copy each into a ROI

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.