mat.reshape giving me an offset in result [closed]

asked 2019-10-14 09:43:09 -0600

updated 2019-10-15 08:49:51 -0600

supra56 gravatar image


I have been struggling with the reshape function. I have a big matrix that I convert into a 1 column mat. When I convert the I column back to the original size, the image has an offset and doesn't fit the original no more.

Here my code more or less (PS. I have simplified it to this that demonstrates my problem): code:

frame = my_Original_mat 
Dim SingleColumn As Mat = frame.Clone.Reshape(0, frame.Cols * frame.Rows)  'makes it a 1 column mat

Dim Mymat As New Mat

 SingleColumn.Col(0).CopyTo(Mymat)   'get the single column back out again

 Dim OriginalShape As Mat = Mymat.Reshape(0, frame.Rows))

CvInvoke.Imshow("Original ", frame.Clone)

CvInvoke.Imshow("OriginalShape ", OriginalShape .Clone)

image description

image description

Sorry for the bad images...but I think you can see that the reshaped one is now shifted down. What am I doing wrong? I need a way to simply extract 1 column at the time from a build up matrix (I concat into this matrix). Let me know if anything else is needed and thanks for the help in advance.

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2019-10-14 09:46:27.969950


sorry, but we can't help with vb or any 3rdparty wrappers.

berak gravatar imageberak ( 2019-10-14 09:47:19 -0600 )edit

@TheoDup. What, if you change this frame.Clone.Reshape(0, frame.Cols * frame.Rows) to frame.Clone.Reshape(1, frame.Cols * frame.Rows)?

supra56 gravatar imagesupra56 ( 2019-10-15 08:52:05 -0600 )edit

@supra56, thanks for the idea and reply/help. However, changing the 0 to 1 will chance the color depth according to the documentation (with 1 = probably gray scale then?). Also, I posted my probleem on emgu wrapper and was also told this is the wrong place (sorry for this). I have in the mean time found out now that the problem is only with column 0. If I take any other column it works as expected. Only column 0 has this kind of offset.

TheoDup gravatar imageTheoDup ( 2019-10-15 13:10:34 -0600 )edit