Matlab 3通道深度图像1通道

Matlab 3通道深度图像1通道,matlab,opencv,image-processing,kinect,Matlab,Opencv,Image Processing,Kinect,我用Kinect v2录制了一个深度视频,当我用MATLAB提取图像时,每个都是3个通道。通常我看到的图像只有一个通道。请任何人告诉我,如何才能使这3频道的形象,以1频道 以下是深度部分的代码: IplImage depth = new IplImage(512, 424, BitDepth.U16, 1); CvVideoWriter DepthWriter; Width = sensor.DepthFrameSource.FrameDescription.Width; DHeight = s

我用Kinect v2录制了一个深度视频,当我用MATLAB提取图像时,每个都是3个通道。通常我看到的图像只有一个通道。请任何人告诉我,如何才能使这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);
IplImage-depth=新的IplImage(512,424,BitDepth.U16,1);
录像机编写部;
宽度=sensor.DepthFrameSource.FrameDescription.Width;
DHHEIGHT=sensor.DepthFrameSource.FrameDescription.Height;
WbDepth=新的可写比图(DWidth,DHeight,96,96,PixelFormats.Gray16,null);
int depthshft=(int)SliderDepth.Value;
使用(DepthFrame DepthFrame=frame.DepthFrameReference.AcquireFrame())
ushort*depthdata=(ushort*)depth.ImageData;
if(depthframe!=null)
{
Depthdata=新的ushort[DWidth*DHeight];
ushort[]Depthloc=新的ushort[DWidth*DHeight];
depthframe.CopyFrameDataToArray(Depthdata);
对于(int i=0;iDepthdata[y*DWidth+x]=(ushort)((Depthdata[y*DWidth+x])到目前为止,每个人都建议您将(假定的)彩色图像转换为灰度。我认为您不应该这样做。
kinect为您提供深度值的“1通道”图像。如果您有彩色(3通道)深度贴图,则说明有问题。转换为灰度将使您丢失深度信息


取而代之的是,首先要弄清楚为什么你的图像被加载为灰度。来源是什么?在读取图像时,转换可能是由Matlab完成的吗?然后你能给它一些标志告诉它不要吗?

将其转换为灰度:。但是,如果图像无论如何都显示为灰色,那么每个通道的值都是相同的实际上,你最好去掉另外两个通道。将3通道深度图像转换为灰度图像会更改深度值?如果每个通道中每个元素的值相同,则不会更改深度值。如果每个元素的值不同,则不能执行此操作。我猜在Matlab中加载图像时使用的函数都会转换为默认情况下有3个频道(例如,像
imshow
does).在这种情况下,转换为灰度不会改变值每个通道中的每个元素都不相同…那么你知道我该怎么做吗?然后你需要发布你如何捕获数据并将其加载到Matlab的代码。你的意思是,在3个通道中录制的深度视频不正确?如果你不指定方式,很难确切知道您可以录制。但是没有,三个通道的深度贴图没有任何意义。这是记录深度流的示例,它与我录制的方式完全相似,正如您在
ImageSource::ToBitmap(DepthFrame)中看到的
方法,将单个深度值转换为RGB三元组。该代码非常奇怪,因为它采用
ushort
深度值并将其转换为3个
字节
值。因此最有可能破坏深度数据。简单:去掉转换为RGB的部分并保存原始深度数据。