Private members in TypeDepth class [closed]

asked 2017-02-01 13:31:48 -0600

updated 2017-02-02 12:25:47 -0600

This is more a question for the developer/contributor team.

I was looking for methods to infer the native type automatically based on the depth value and came across the TypeDepth class on core/traits.hpp. Unfortunately all its members are private and the thing is not really usable nor used anywhere.

Any particular reasons for this? e.g.: it's implementation/architecture dependent and therefore cannot be used reliably, something of that sort.

If there's no actual reason, could you expose the members in the next releases?

Edit: Intended use case

I wanted to generate a colormap representation for a matrix of type CV_32FC1, but currently the applyColormap only works with matrices of type CV_8UC1 or CV_8UC3. In order to overcome this limitation, I wrote a function which which receives a generic cv::Mat, infers the underlying depth and channels, generates an intermediate matrix which will be a normalized version of the input matrix i.e., the maximum value found on input will correspond to 255 and the minimum value to 0, with everything else in between will be mapped linearly. I wanted to this generically, so that it works with other types like CV_16S, CV_16U, CV_32F, CV_64F, etc...

Below is an initial version of what was going to be my implementation.

template<int OpenCvDepthT> void
colormap ( const cv::Mat &input,
           const cv::ColormapTypes colormap,
           cv::Mat &out)
{
  typedef typename cv::TypeDepth<OpenCvDepthT>::value_type T;

  auto const minmax = std::minmax_element((const T*)input.data , (const T*) input.dataend);
  const T range = *minmax.second - *minmax.first;

  // create normalized matrix
  cv::Mat tmp (input.size (), CV_MAKETYPE (CV_8U, input.channels ()));

  const T* ptr1 = (T *) input.data;
  uint8_t* ptr2 = (uint8_t *) tmp.data;
  for (; ptr1 != (const T *) input.dataend && ptr2 != (uint8_t *)tmp.dataend; ++ptr1, ++ptr2)
    *ptr2 = (uint8_t) ((T) 255 * (*ptr1 - *minmax.first) / range);

  cv::applyColorMap (tmp, out, colormap);
}

Cheers

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-07 00:19:14.111949

Comments

what are you trying to achieve ?

(a use-case might be helpful)

berak gravatar imageberak ( 2017-02-01 13:46:05 -0600 )edit

Added the use case.

Sergio Agostinho gravatar imageSergio Agostinho ( 2017-02-01 15:52:53 -0600 )edit

honestly, imho, you only tried re-inventing NORM_MINMAX in a slower, overcomplicated way.

berak gravatar imageberak ( 2017-02-01 17:12:36 -0600 )edit
1

Based on your tips I managed to reduce my implementation to something a lot more pleasant. Thanks!

void
colormap ( const cv::Mat &input,
           const cv::ColormapTypes colormap,
           cv::Mat &out)
{
  cv::Mat tmp, tmp2;
  cv::normalize (input, tmp, 255, 0, cv::NORM_MINMAX);
  tmp.convertTo (tmp2, CV_8U);
  cv::applyColorMap (tmp2, out, colormap);
}

Now back to the original topic, those TypeDepth traits are useless for the time being.

Sergio Agostinho gravatar imageSergio Agostinho ( 2017-02-01 17:42:01 -0600 )edit

but i think, you're right on the TypeDepth. -- as it is, it's utterly useless,and never actually used anywhere, and might be something redundant.

are you bold enough, to raise an official issue here (as in: imho, the whole thing should be removed, not improved)? ;)

berak gravatar imageberak ( 2017-02-02 02:04:30 -0600 )edit

Sure thing. I was going to originally, but since it's not really an issue I decided to use the Q&A forum first. I wouldn't go as far as removing it, since I do see a use for it.

Sergio Agostinho gravatar imageSergio Agostinho ( 2017-02-02 12:55:50 -0600 )edit