-1

concatenated image with gray and gradient magnitude

gradient magnitude image

input color image

i cant concatenate input color image and gradient magnitude

input = cv2.imread('figures/output.png')# 3 channel
input.astype(np.float32)
gray = cv2.cvtColor(input, cv2.COLOR_BGR2GRAY)
dx = cv2.Sobel(gray, cv2.CV_32F, 1, 0)  # float 
dy = cv2.Sobel(gray, cv2.CV_32F, 0, 1)

mag = cv2.magnitude(dx, dy)  # gradient magnitude , no channel
mag = np.clip(mag, 0, 255).astype(np.uint8)  # 255보다 커질 수 있으므로 saturate 연산

cv2.imshow('magnitude', mag)

addv = cv2.vconcat((input, mag)) # error 

i get an error that addv part but gray = cv2.cvtColor(input, cv2.COLOR_BGR2GRAY) gray with gradient magnitud concatenating is fine

cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-1syr35c1/opencv/modules/core/src/matrix_operations.cpp:111: error:
 (-215:Assertion failed) src[i].dims <= 2 && src[i].cols == src[0].cols && src[i].type() == src[0].type() in function 'vconcat'

i dont know why

  • What does error say? – Epsi95 Feb 15 '21 at 06:11
  • error part = addv = cv2.vconcat((im, mag)) # error error message = cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-1syr35c1/opencv/modules/core/src/matrix_operations.cpp:111: error: (-215:Assertion failed) src[i].dims <= 2 && src[i].cols == src[0].cols && src[i].type() == src[0].type() in function 'vconcat' – 허니브레드 Feb 15 '21 at 06:12
  • For vconcat both image should have same number of channels and same width – Epsi95 Feb 15 '21 at 06:16
  • i know input image is 3channel and magnitude is no channel so it cant be concatenate but i have to do i'm coding followed paper "https://openaccess.thecvf.com/content_CVPR_2020/papers/Wan_Reflection_Scene_Separation_From_a_Single_Image_CVPR_2020_paper.pdf" – 허니브레드 Feb 15 '21 at 06:18
  • paper said "we concatenate the input image with its corresponding gradient image as the input to the separation network " – 허니브레드 Feb 15 '21 at 06:20
  • you mean `cv2.vconcat((img, mag))` right? not `cv2.vconcat((im, mag))` <-- img not im – Epsi95 Feb 15 '21 at 06:22
  • no, addv = cv2.vconcat((im, mag)) is right im=> input color image, mag => gradient magnitude image mag is image ill show you – 허니브레드 Feb 15 '21 at 06:25
  • What is `im.shape` and `mag.shape` and `img.shape`? – Epsi95 Feb 15 '21 at 06:31
  • im.shape(input color image): (282, 366, 3) img.shape(input gray image): (282, 366) mag.shape(gradient magnitude image): (282, 366) concatenating input gray image and gradient magnitude image => good concatenating input color image and gradient magnitude image => error – 허니브레드 Feb 15 '21 at 06:36
  • That is what i am saying,` vstack` both channel should have the same channels – Epsi95 Feb 15 '21 at 06:46
  • how to make both image channel same? – 허니브레드 Feb 15 '21 at 06:48
  • check the answer – Epsi95 Feb 15 '21 at 06:50

1 Answers1

0
import cv2 
from skimage import io
import numpy as np

im = cv2.imread('figures/output.png')# 3 channel
im.astype(np.float32)
img = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
dx = cv2.Sobel(img, cv2.CV_32F, 1, 0)  # float 
dy = cv2.Sobel(img, cv2.CV_32F, 0, 1)

mag = cv2.magnitude(dx, dy)  # gradient magnitude , no channel
mag = np.clip(mag, 0, 255).astype(np.uint8)  # 255보다 커질 수 있으므로 saturate 연산

cv2.imshow('magnitude', mag)
mag = cv2.cvtColor(mag, cv2.COLOR_GRAY2RGB) # convert mag to RGB
addv = cv2.vconcat((im, mag))
Epsi95
  • 8,832
  • 1
  • 16
  • 34