我有一个包含内容的.las
文件,如下所示:
array([( 860297, 472942, 67187, 11051, 73, 0, 0, 0, 1, 12079, 11051, 9252),
( 859318, 473132, 67336, 8995, 73, 0, 0, 0, 1, 9252, 8995, 9509),
( 859941, 473665, 67550, 12079, 73, 0, 0, 0, 1, 12079, 12850, 10023),
...,
(1057593, 1184341, 75212, 19018, 73, 0, 0, 0, 1, 20303, 19275, 16191),
(1057764, 1184161, 74734, 14906, 73, 0, 0, 0, 1, 15934, 14906, 13878),
(1057548, 1184058, 74881, 26214, 73, 0, 0, 0, 1, 28784, 25957, 21074)],
dtype=[('X', '<i4'), ('Y', '<i4'), ('Z', '<i4'), ('intensity', '<u2'), ('bit_fields', 'u1'),
('raw_classification', 'u1'), ('scan_angle_rank', 'i1'), ('user_data', 'u1'),
('point_source_id', '<u2'), ('red', '<u2'), ('green', '<u2'), ('blue', '<u2')])
正如我在.las文件中发现的,RGB中的值以16位颜色存储。我编写了2个函数-将颜色转换为8位:
opened_file = open("my.las") #example
colors = opened_file.points[["red", "green", 'blue']]
>>> array([(12079, 11051, 9252), (9252, 8995, 9509), (12079, 12850, 10023), ...])
def eightbitify(colour):
return colour/256
接下来,我尝试将颜色转换为HSV
,因此我可以过滤特定的颜色:
def to_hsv(rgb: np.ndarray):
empty_image = np.zeros((1, 1, 3), dtype=np.uint8)
empty_image[0, 0] = list(reversed(rgb))
hsv = cv2.cvtColor(empty_image, cv2.COLOR_RGB2HSV)
return list(reversed(hsv[0, 0]))
我并没有找到更好的解决方案,因为OpenCV需要图像-所以我创建了一个像素的图像并进行了转换(非常难看:/)。问题是我收到的值与任何internet RGB-HSV计算器的结果都不匹配。 我以这种方式使用这些功能:
def convert_color(rgb_16: np.ndarray)->np.ndarray:
converted_color = np.array([int(eightbitify(rgb_16[0])), int(eightbitify(rgb_16[1])), int(eightbitify(rgb_16[2]))])
converted_hsv = to_hsv(converted_color)
return converted_hsv
for color in colors:
converted = convert_color(color)
所以我的问题是:
1.从我的opened_file.points
初始数组将RGB值转换为HSV的最佳方法是什么?
2.如何仅使用numpy从opened_file.points
中过滤特定颜色?我可以对RGB值等应用一些转换功能吗?
不幸的是,我对numpy的经验很少,所以我需要帮助。谢谢大家!
我不熟悉你的图像类型,但希望能在Numpy和OpenCV方面帮助你
目前,我不知道图像的形状,所以它显示为一条4400万像素的长线,但它只需要一个
reshape()
来纠正它。请注意,mask
中的每个真/假值都将作为像素列表的索引,并指示该像素是否为绿色您可能需要处理
range
参数的上下两个值-请参阅我的答案hereStack Overflow user@Nathance制作了一个带有滑块here的相当整洁的HSV颜色选择器
相关问题 更多 >
编程相关推荐