1

I'm using version 1.0.0 (unfortunately can not use newer one) for basic image operations like addition, division etc.

Data structures i'm using are defined like so:

CvMat m1 = cvCreateMat(w, h, CV_16U);
CvMat m2 = cvCreateMat(w, h, CV_16U);
CvMat m3 = cvCreateMat(w, h, CV_16U);

and contain 16bit unsigned grayscale raw images.

Operations like addition, substraction are working just fine. On the other hand, operation cvDiv(m1, m2, m3); produces Division by zero exception.

It seems like mats have to be converted to CV_32F, but i could not find a way how to properly convert them using .

If i convert them manually (by my own function) i'm getting Violation reading location exception.

My questions are following:

  1. How to convert CvMat from CV_16U to CV_32F

  2. How to correctly divide two images using cvDiv function

kocica
  • 6,412
  • 2
  • 14
  • 35
  • `cvConvertScale` for the conversion. (BTW, what exactly do you mean by "convert them by hand"?) – Dan Mašek Jul 31 '18 at 14:39
  • Iam sorry for this misleading phrase. I have meant that i tried to create my own `cvDiv` function. Thanks for the tip, i will try out tomorrow and let you know. The scale for conversion from `16U` to `32F` should be 2^16/(Max-Min) -- right ? According to [this](https://stackoverflow.com/questions/14539498/change-type-of-mat-object-from-cv-32f-to-cv-8u). – kocica Jul 31 '18 at 15:39
  • 1
    The scaling is necessary only if you're going to use functions that expect floating point images to have values in range [0,1]. To map the full range of 16U to [0,1], you'd use scaling factor (1.0/((2^16)-1))). However, if all you need to do is some arithmetics, just leave the scale at 1 (or use the [`cvConvert`](http://opencv.jp/opencv-1.0.0_org/docs/ref/opencvref_cxcore.htm#decl_cvConvertScale) macro). – Dan Mašek Jul 31 '18 at 16:01
  • @DanMašek `cvConvert` works great and so `cvDiv` now. Thanks. It is not easy to search for such an old functions if everybody is using new `C++` versions these days. Could you, please, post it as answer, so iam able to mark this question as answered ? It may help somebody in the future. – kocica Aug 01 '18 at 06:31

0 Answers0