已有扫描图片及扫描图片颗粒中心点的坐标,在扫描图片中用红点标注出中心点坐标的matlab代码
时间: 2024-11-22 07:38:56 浏览: 27
在MATLAB中,如果你已经有了扫描图片以及每个颗粒的中心点坐标,你可以使用`scatter`函数将这些点标记出来。以下是一个简单的示例:
```matlab
% 假设你已经有了名为image和centers的变量,分别表示扫描图片和中心点坐标
% image是一个矩阵,centers是一个包含两个列的数组,每行代表一个粒子的(x, y)坐标
% 确保图片是以RGB格式展示
if isa(image, 'uint8')
image = rgb2gray(image);
end
% 创建一个新的图像窗口显示原始图片
figure;
imshow(image);
% 使用scatter函数添加红色标记的点
hold on; % 需要保持原图可见
scatter(centers(:,2), centers(:,1), 'filled', 'MarkerSize', 5, 'MarkerFaceColor', 'red');
% 添加标签和标题
title('Scanned Image with Particle Centers');
xlabel('X Coordinate');
ylabel('Y Coordinate');
% 关闭hold以便下一次操作不会覆盖之前的图像
hold off;
% 如果你想保存这张带有标记的图片,可以这样做
im_with_markers = insertObjectAnnotation(image, 'rectangle', centers, 'Text', 'Particle Center', 'Position', 'SouthEast', 'Color', 'white', 'EdgeColor', 'none', 'LineWidth', 0);
saveas(im_with_markers, 'image_with_particle_centers.png');
```
这段代码会在图像上显示每个颗粒的中心点,用红色圆圈标识。如果想改变标记的颜色、大小或者其他属性,可以直接调整`scatter`函数中的参数。
阅读全文
相关推荐












