将点云Z向数据生成伪彩图、灰度图(最小值和最大值区间映射RGB三通道)

本文主要是介绍将点云Z向数据生成伪彩图、灰度图(最小值和最大值区间映射RGB三通道),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

C# 指针遍历+for循环多线程

public unsafe static HObject PointXYZ_To_GrayColorHobject(ref PointXYZ[] PointCloudData, int ImgWidth, int ImgHeight, float ZMin, float ZMax,out HObject colorImg)
{try{HObject ImgHobject = null;colorImg = null;if (PointCloudData == null) return ImgHobject;//归一化后按 0-1/3  1/3-2/3  2/3-1 进行颜色映射float cut1 = 1.0f / 3.0f;float cut2 = 2.0f / 3.0f;int numPoints = PointCloudData.Length;float RangeZ = ZMax - ZMin;//点云数据范围float coefficient = RangeZ > 0 ? 255 * 1.0f / RangeZ : 0;//灰度系数//byte[] grayArr = new byte[numPoints];IntPtr colorPtr = Marshal.AllocHGlobal(numPoints * 3 * sizeof(byte));//分配伪彩图RGB内存IntPtr grayPtr = Marshal.AllocHGlobal(numPoints * sizeof(byte));//分配灰度图内存int numProcessedPoints = ImgWidth - (ImgWidth % 4); // 可以处理的点的数量(4的倍数)fixed (PointXYZ* pData = PointCloudData){float* pHeight = (float*)pData;byte* colorPtrTemp = (byte*)colorPtr;byte* grayPtrTemp = (byte*)grayPtr;Parallel.For(0, ImgHeight, Row =>{float* PRowIndexPointData = pHeight + Row * ImgWidth * 3;//点云指针byte* pDest = colorPtrTemp + Row * 3 * ImgWidth;//伪彩图图像遍历指针byte* pGrayDest = grayPtrTemp + Row * ImgWidth;//灰度图图像遍历指针for (int Col = 0; Col < numProcessedPoints; Col += 4){float height1 = PRowIndexPointData[2];float height2 = PRowIndexPointData[5];float height3 = PRowIndexPointData[8];float height4 = PRowIndexPointData[11];#region gray灰度映射pGrayDest[0] = (byte)((height1 >= ZMin && height1 <= ZMax) ? (height1 - ZMin) * coefficient : 0);pGrayDest[1] = (byte)((height2 >= ZMin && height2 <= ZMax) ? (height2 - ZMin) * coefficient : 0);pGrayDest[2] = (byte)((height3 >= ZMin && height3 <= ZMax) ? (height3 - ZMin) * coefficient : 0);pGrayDest[3] = (byte)((height4 >= ZMin && height4 <= ZMax) ? (height4 - ZMin) * coefficient : 0);#endregion#region color颜色映射//height1  normalval1if (height1 >= ZMin && height1 <= ZMax){float normalVal1 = (height1 - ZMin) / RangeZ;if (normalVal1 <= cut1){pDest[0] = 0;pDest[1] = (byte)(3 * normalVal1 * 255);pDest[2] = 255;}else if (normalVal1 > cut1 && normalVal1 <= cut2){pDest[0] = (byte)((3 * normalVal1 - 1) * 255);pDest[1] = 255;pDest[2] = (byte)((-3 * normalVal1 + 2) * 255);}else if (normalVal1 > cut2){pDest[0] = 255;pDest[1] = (byte)((-3 * normalVal1 + 3) * 255);pDest[2] = 0;}}else{pDest[0] = 0;pDest[1] = 0;pDest[2] = 0;}//height2  normalval2if (height2 >= ZMin && height2 <= ZMax){float normalVal2 = (height2 - ZMin) / RangeZ;if (normalVal2 <= cut1){pDest[3] = 0;pDest[4] = (byte)(3 * normalVal2 * 255);pDest[5] = 255;}else if (normalVal2 > cut1 && normalVal2 <= cut2){pDest[3] = (byte)((3 * normalVal2 - 1) * 255);pDest[4] = 255;pDest[5] = (byte)((-3 * normalVal2 + 2) * 255);}else if (normalVal2 > cut2){pDest[3] = 255;pDest[4] = (byte)((-3 * normalVal2 + 3) * 255);pDest[5] = 0;}}else{pDest[3] = 0;pDest[4] = 0;pDest[5] = 0;}//height3  normalval3if (height3 >= ZMin && height3 <= ZMax){float normalVal3 = (height3 - ZMin) / RangeZ;if (normalVal3 <= cut1){pDest[6] = 0;pDest[7] = (byte)(3 * normalVal3 * 255);pDest[8] = 255;}else if (normalVal3 > cut1 && normalVal3 <= cut2){pDest[6] = (byte)((3 * normalVal3 - 1) * 255);pDest[7] = 255;pDest[8] = (byte)((-3 * normalVal3 + 2) * 255);}else if (normalVal3 > cut2){pDest[6] = 255;pDest[7] = (byte)((-3 * normalVal3 + 3) * 255);pDest[8] = 0;}}else{pDest[6] = 0;pDest[7] = 0;pDest[8] = 0;}//height4  normalval4if (height4 >= ZMin && height4 <= ZMax){float normalVal4 = (height4 - ZMin) / RangeZ;if (normalVal4 <= cut1){pDest[9] = 0;pDest[10] = (byte)(3 * normalVal4 * 255);pDest[11] = 255;}else if (normalVal4 > cut1 && normalVal4 <= cut2){pDest[9] = (byte)((3 * normalVal4 - 1) * 255);pDest[10] = 255;pDest[11] = (byte)((-3 * normalVal4 + 2) * 255);}else if (normalVal4 > cut2){pDest[9] = 255;pDest[10] = (byte)((-3 * normalVal4 + 3) * 255);pDest[11] = 0;}}else{pDest[9] = 0;pDest[10] = 0;pDest[11] = 0;}#endregionpGrayDest += 4;pDest += 12;PRowIndexPointData += 12;}for (int Col = numProcessedPoints; Col < ImgWidth; Col++){float height1 = PRowIndexPointData[2];#region gray灰度映射pGrayDest[0] = (byte)((height1 >= ZMin && height1 <= ZMax) ? (height1 - ZMin) * coefficient : 0);#endregion#region color颜色映射//height1  normalval1if (height1 >= ZMin && height1 <= ZMax){float normalVal1 = (height1 - ZMin) / RangeZ;if (normalVal1 <= cut1){pDest[0] = 0;pDest[1] = (byte)(3 * normalVal1 * 255);pDest[2] = 255;}else if (normalVal1 > cut1 && normalVal1 <= cut2){pDest[0] = (byte)((3 * normalVal1 - 1) * 255);pDest[1] = 255;pDest[2] = (byte)((-3 * normalVal1 + 2) * 255);}else if (normalVal1 > cut2){pDest[0] = 255;pDest[1] = (byte)((-3 * normalVal1 + 3) * 255);pDest[2] = 0;}}else{pDest[0] = 0;pDest[1] = 0;pDest[2] = 0;}#endregionpGrayDest++;pDest += 3;PRowIndexPointData += 3;}});}HOperatorSet.GenImage1(out ImgHobject, "byte", ImgWidth, ImgHeight, grayPtr);HOperatorSet.GenImageInterleaved(out colorImg, colorPtr, "rgb", ImgWidth, ImgHeight, -1, "byte", ImgWidth, ImgHeight, 0, 0, -1, 0);Marshal.FreeHGlobal(colorPtr);Marshal.FreeHGlobal(grayPtr);return ImgHobject;}catch{colorImg = null;return null;}
}

 

 

这篇关于将点云Z向数据生成伪彩图、灰度图(最小值和最大值区间映射RGB三通道)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1035211

相关文章

解决IDEA报错:编码GBK的不可映射字符问题

《解决IDEA报错:编码GBK的不可映射字符问题》:本文主要介绍解决IDEA报错:编码GBK的不可映射字符问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录IDEA报错:编码GBK的不可映射字符终端软件问题描述原因分析解决方案方法1:将命令改为方法2:右下jav

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格

python处理带有时区的日期和时间数据

《python处理带有时区的日期和时间数据》这篇文章主要为大家详细介绍了如何在Python中使用pytz库处理时区信息,包括获取当前UTC时间,转换为特定时区等,有需要的小伙伴可以参考一下... 目录时区基本信息python datetime使用timezonepandas处理时区数据知识延展时区基本信息

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Pandas统计每行数据中的空值的方法示例

《Pandas统计每行数据中的空值的方法示例》处理缺失数据(NaN值)是一个非常常见的问题,本文主要介绍了Pandas统计每行数据中的空值的方法示例,具有一定的参考价值,感兴趣的可以了解一下... 目录什么是空值?为什么要统计空值?准备工作创建示例数据统计每行空值数量进一步分析www.chinasem.cn处

如何使用 Python 读取 Excel 数据

《如何使用Python读取Excel数据》:本文主要介绍使用Python读取Excel数据的详细教程,通过pandas和openpyxl,你可以轻松读取Excel文件,并进行各种数据处理操... 目录使用 python 读取 Excel 数据的详细教程1. 安装必要的依赖2. 读取 Excel 文件3. 读

Spring 请求之传递 JSON 数据的操作方法

《Spring请求之传递JSON数据的操作方法》JSON就是一种数据格式,有自己的格式和语法,使用文本表示一个对象或数组的信息,因此JSON本质是字符串,主要负责在不同的语言中数据传递和交换,这... 目录jsON 概念JSON 语法JSON 的语法JSON 的两种结构JSON 字符串和 Java 对象互转

C++如何通过Qt反射机制实现数据类序列化

《C++如何通过Qt反射机制实现数据类序列化》在C++工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作,所以本文就来聊聊C++如何通过Qt反射机制实现数据类序列化吧... 目录设计预期设计思路代码实现使用方法在 C++ 工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作。由于数据类

SpringBoot使用GZIP压缩反回数据问题

《SpringBoot使用GZIP压缩反回数据问题》:本文主要介绍SpringBoot使用GZIP压缩反回数据问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot使用GZIP压缩反回数据1、初识gzip2、gzip是什么,可以干什么?3、Spr