Farthest sampling on 3d mesh with mesh kept

3D mesh的farthest sampling与2D 图片的采样原理类似(http://blog.csdn.net/seamanj/article/details/52028904).

随机给个初始点,然后根据初始点,然后算出最远的n-1个点,  n为我们需要采样的个数

最后以这个n个点为初始点,算出mesh上的距离场


主要代码:


% test for farthest point sampling on 3D meshes

n = 300;
name = 'elephant-50kv';
[vertex,faces] = read_mesh(name);
options.name = name;

if size(vertex,1)>size(vertex,2)
    vertex = vertex';
end
if size(faces,1)>size(faces,2)
    faces = faces';
end


save_images = 0;

% plot sampling location
i = 0;
landmark = [];
for nbr_landmarks = [50]% 500 1000 2000 5000 10000]  % 100:50:500
    i = i+1;
    
    disp('Perform farthest point sampling.');
    landmark = perform_farthest_point_sampling_mesh( vertex,faces, landmark, nbr_landmarks-length(landmark) );
    %这步会根据farthest point sampling原则选出nbr_landmarks-length(landmark)个样本点
    % compute the associated triangulation
    [D,Z,Q] = perform_fast_marching_mesh(vertex, faces, landmark);
    %初始点为landmark,然后算距离
    % display
    col = D; col(col==Inf) = 0;
    col = perform_histogram_equalization(col, linspace(0,1,length(col)));
    options.face_vertex_color = col;
    hold on;
    plot_mesh(vertex, faces, options);
    hold off;
    colormap jet(256);
    camlight;
    shading interp;

end


运行结果如下:



完整源代码




当然可以!下面是一个使用Farthest Point Sampling (FPS)算法找出文件中距离最远的3张图像,并返回图像名的Python代码示例: ```python import os import numpy as np from PIL import Image def compute_distance(image1, image2): # 计算两张图像的距离,可以使用任意方法 # 这里以欧氏距离为例 return np.linalg.norm(image1 - image2) def farthest_point_sampling(images_dir, num_samples=3): # 获取目录下所有图像文件名 image_files = [file for file in os.listdir(images_dir) if file.endswith('.jpg') or file.endswith('.png')] # 随机选择第一个样本 sample_indices = [np.random.randint(len(image_files))] for _ in range(num_samples-1): max_distance = float('-inf') farthest_index = None # 遍历所有图像文件 for i, image_file in enumerate(image_files): if i not in sample_indices: # 加载图像并转换为灰度图 image_path = os.path.join(images_dir, image_file) image = np.array(Image.open(image_path).convert('L')) # 计算当前图像与已选择样本的距离之和 total_distance = 0 for index in sample_indices: sample_path = os.path.join(images_dir, image_files[index]) sample_image = np.array(Image.open(sample_path).convert('L')) total_distance += compute_distance(image, sample_image) # 更新最远距离和索引 if total_distance > max_distance: max_distance = total_distance farthest_index = i # 将最远的图像索引添加到样本列表中 sample_indices.append(farthest_index) # 返回最远的图像文件名 return [image_files[index] for index in sample_indices] # 示例使用 images_directory = 'path/to/images' farthest_images = farthest_point_sampling(images_directory, num_samples=3) print(farthest_images) ``` 你需要将 `images_directory` 替换为包含图像文件的实际路径。此代码将在指定目录中找到距离最远的3张图像,并返回它们的文件名。请确保在运行代码之前安装必要的依赖项(numpy、PIL)。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值