title: Square root of a OpenCV's grey image using SSE
body: <p>given a grey cv::Mat (CV_8UC1) I want to return another cv::Mat containing the square root of the elements (CV_32FC1) and I want to do it with SSE2 intrinsics. I am having some problems with the conversion from 8-bit values to 32 float values to perform the square root. I would really appreciate any help. This is my code for now(it does not give correct values):</p>
  
  <pre><code>uchar *source = (uchar *)cv::alignPtr(image.data, 16);
  float *sqDataPtr = cv::alignPtr((float *)Squared.data, 16); 
  for (x = 0; x &lt; (pixels - 16); x += 16) {
      __m128i a0 = _mm_load_si128((__m128i *)(source + x));
  
      __m128i first8 = _mm_unpacklo_epi8(a0, _mm_set1_epi8(0));
      __m128i last8 = _mm_unpackhi_epi8(a0, _mm_set1_epi8(0));
  
      __m128i first4i = _mm_unpacklo_epi16(first8, _mm_set1_epi16(0));
      __m128i second4i = _mm_unpackhi_epi16(first8, _mm_set1_epi16(0));
      __m128 first4 = _mm_cvtepi32_ps(first4i);
      __m128 second4 = _mm_cvtepi32_ps(second4i);
  
      __m128i third4i = _mm_unpacklo_epi16(last8, _mm_set1_epi16(0));
      __m128i fourth4i = _mm_unpackhi_epi16(last8, _mm_set1_epi16(0));
      __m128 third4 = _mm_cvtepi32_ps(third4i);
      __m128 fourth4 = _mm_cvtepi32_ps(fourth4i);
  
      //  Store
      _mm_store_ps(sqDataPtr + x, _mm_sqrt_ps(first4));
      _mm_store_ps(sqDataPtr + x + 4, _mm_sqrt_ps(second4));
      _mm_store_ps(sqDataPtr + x + 8, _mm_sqrt_ps(third4));
      _mm_store_ps(sqDataPtr + x + 12, _mm_sqrt_ps(fourth4));
  }
  </code></pre>