【问题标题】:3 channel depth image 1 channel3 通道深度图像 1 通道
【发布时间】:2015-06-09 14:19:07
【问题描述】:

我使用 Kinect v2 录制了深度视频,当我使用 MATLAB 提取图像时,每个 image 是 3 通道。通常我看到的图像只有 1 个通道。请任何人告诉我如何将这个 3 通道图像转换为 1 通道?

这里是深度部分的代码:

IplImage depth = new IplImage(512, 424, BitDepth.U16, 1);
CvVideoWriter DepthWriter;
Width = sensor.DepthFrameSource.FrameDescription.Width;
DHeight = sensor.DepthFrameSource.FrameDescription.Height;
WbDepth = new WriteableBitmap(DWidth, DHeight, 96, 96, PixelFormats.Gray16, null);
int depthshft = (int)SliderDepth.Value;
using (DepthFrame depthframe = frame.DepthFrameReference.AcquireFrame())
ushort* depthdata = (ushort*)depth.ImageData;
if (depthframe != null)
   {
    Depthdata = new ushort[DWidth * DHeight];
    ushort[] Depthloc = new ushort[DWidth * DHeight];
    depthframe.CopyFrameDataToArray(Depthdata);
    for (int i = 0; i < DWidth * DHeight; i++)
        {
          Depthloc[i] = 0x1000;
        }
        colorspacePoint = new ColorSpacePoint[DWidth * DHeight];
        depthspacePoint = new DepthSpacePoint[CWidth * CHeight];
        sensor.CoordinateMapper.MapDepthFrameToColorSpace(Depthloc, colorspacePoint);
        for (int y = 0; y < DHeight; y++)
            {
            for (int x = 0; x < DWidth; x++)
                {
                if (depthshft != 0)
                   {
                    Depthdata[y * DWidth + x] = (ushort)((Depthdata[y * DWidth + x]) << depthshft);
                   }

                 }
             }
         depth.CopyPixelData(Depthdata);
 }
WbDepth.WritePixels(new Int32Rect(0, 0, DWidth, DHeight), Depthdata, strideDep, 0);
ImageDepth.Source = WbDepth;
if (depth != null && DepthWriter.FileName != null) Cv.WriteFrame(DepthWriter, depth);
Cv.ReleaseVideoWriter(DepthWriter);
if (CheckBox_saveD.IsChecked == true)
DepthWriter = new CvVideoWriter(string.Format("{1}\\Scene{0}_DepthRecord.avi", scene, TextBlock_saveloca.Text.ToString()), FourCC.Default, 30.0f, new CvSize(512, 424));
CheckBox_saveD.IsEnabled = false;
if (CheckBox_saveD.IsChecked == true) Cv.ReleaseVideoWriter(DepthWriter);

谢谢

【问题讨论】:

  • 将其转换为灰度:mathworks.com/help/matlab/ref/rgb2gray.html。但是,如果图像无论如何都显示为灰色,那么每个通道都有相同的值,实际上你最好放弃其他两个通道。
  • 将3通道深度图像转换为灰度图像改变深度值?
  • 如果每个元素的值在每个通道中都相同,则不会。如果它们不同,那么你不能这样做。不过我的猜测是,您用来在 Matlab 中加载图像的任何函数默认转换为 3 个通道(例如 imshow 所做的)。在这种情况下,转换为灰度不会改变值
  • 每个频道的每个元素都不相同......那么知道我该怎么做吗?
  • 然后你需要发布你如何捕获数据并将其加载到matlab中的代码

标签: matlab opencv image-processing kinect


【解决方案1】:

到目前为止,每个人都建议您将(假定的)彩色图像转换为灰度图像。 我认为您不应该这样做。 kinect 为您提供深度值的“1 通道”图像。如果你有一个彩色(3 通道)深度图,那就有问题了。然后转换为灰度会让您失去深度信息

相反,首先要尝试弄清楚为什么您的图像以灰度加载。来源是什么?读取图像时是否可以通过 Matlab 完成转换?然后你可以给它一些标志告诉它不要吗?

【讨论】:

  • 你的意思是3通道录制的深度视频不正确?
  • 如果您不指定录制方式,则很难准确知道。但是不,具有三个通道的深度图没有意义。
  • 这里是录制深度流link的样例,和我录制的方式一模一样
  • 正如您在ImageSource::ToBitmap(DepthFrame frame) 方法中看到的那样,单个深度值被转换为RGB-triplet。该代码非常奇怪,因为它采用 ushort 深度值并将其转换为 3 个 byte 值。从而很可能破坏深度数据。
  • 简单:去掉转换为RGB的部分,保存原始深度数据。
猜你喜欢
  • 1970-01-01
  • 2012-04-15
  • 2020-08-08
  • 1970-01-01
  • 1970-01-01
  • 2019-04-02
  • 1970-01-01
  • 2019-03-15
  • 2019-01-19
相关资源
最近更新 更多