title: Apply an openCV Lookup Table (LUT) on a single channel image
body: <p>My goal is to take an image, convert it to LAB color space, and then apply a custom lookup table on only the lightness channel and display that.  The LUT would apply a gradient from blue to red - so my output image would show the brightest parts of the image in red, and the darkest in blue.</p>
  
  <pre><code>void MainWindow::convertBGRMatToLAB(const cv::Mat inputMat)
  {
      // Create lookup table (LUT)
      cv::Mat lookupTable(1, 256, CV_8UC(3));
      for (int i=0; i&lt;256; i++)
      {
          lookupTable.at&lt;cv::Vec3b&gt;(i)[0]= 255-i; // first channel  (B)
          lookupTable.at&lt;cv::Vec3b&gt;(i)[1]= 0;     // second channel (G)
          lookupTable.at&lt;cv::Vec3b&gt;(i)[2]= 255+i; // ...            (R)
      }
  
      // Convert to LAB color space.
      cv::Mat convertedLAB;
      cv::cvtColor(inputMat, convertedLAB, CV_BGR2Lab);
  
      // Isolate the L, A, B channels.
      cv::Mat convertedLABSplit[3];
      cv::split(convertedLAB, convertedLABSplit);
  
      // Apply our custom lookup table to L channel.
      cv::Mat outputMat(inputMat.rows, inputMat.cols, CV_8UC3);
      cv::LUT(convertedLABSplit[0], lookupTable, outputMat); // Program crashes here.
      //cv::LUT(inputMat, lookupTable, outputMat); // This works (but not what I am looking to do).
  
      // Show the output image
      cv::imshow("Output Image", outputMat);
  }
  </code></pre>
  
  <p>But when I run my (Qt) application I get a Microsoft Visual C++ Runtime Library Debug error:
  <a href="https://i.stack.imgur.com/KTWVw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KTWVw.png" alt="VC++ Runtime error"></a></p>
  
  <p>and:</p>
  
  <pre><code>OpenCV Error: Assertion failed ((lutcn == cn || lutcn == 1) &amp;&amp; _lut.total() == 256 &amp;&amp; _lut.isContinuous() &amp;&amp; (depth == 0 || depth == 1)) in cv::LUT, file C:\OpenCV\3.4.0\source\opencv-3.4.0\modules\core\src\convert.cpp, line 4552
  </code></pre>
  
  <p>I believe the issue is related to applying a LUT to a single channel image, as the above code runs if I apply the LUT to just the input image.  So instead of:</p>
  
  <pre><code>cv::LUT(convertedLABSplit[0], lookupTable, outputMat);
  </code></pre>
  
  <p>I change it to:</p>
  
  <pre><code>cv::LUT(inputMat, lookupTable, outputMat);
  </code></pre>
  
  <p>But I would like to apply my LUT to only the L channel in the LAB color space and discard the A and B channels.</p>
  
  <p>Is the problem related to how I am creating my LUT?  How should I create a LUT like this for a single channel image?</p>