Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
考虑像黑白图像此
![]() 我要做的是找到白点最密集的区域。在这种情况下,有20-21个这样的密集区域(即,点的簇构成一个密集区域)。 谁能给我任何有关如何实现的提示? 回答: 如果可以访问“ 图像处理工具箱” ,则可以利用其中包含的许多过滤和形态学操作。使用函数imfilter , imclose和imregionalmax ,这是解决问题的一种方法: % Load and plot the image data: imageData = imread('lattice_pic.jpg'); % Load the lattice image subplot(221); imshow(imageData); title('Original image'); % Gaussian-filter the image: gaussFilter = fspecial('gaussian', [31 31], 9); % Create the filter filteredData = imfilter(imageData, gaussFilter); subplot(222); imshow(filteredData); title('Gaussian-filtered image'); % Perform a morphological close operation: closeElement = strel('disk', 31); % Create a disk-shaped structuring element closedData = imclose(filteredData, closeElement); subplot(223); imshow(closedData); title('Closed image'); % Find the regions where local maxima occur: maxImage = imregionalmax(closedData); maxImage = imdilate(maxImage, strel('disk', 5)); % Dilate the points to see % them better on the plot subplot(224); imshow(maxImage); title('Maxima locations'); 这是上面的代码创建的图像: ![]() 为了让事情看起来不错,我只是一直在尝试为高斯滤波器(使用创建的参数的几个不同的组合fspecial )和结构元素(使用创建strel )。但是,一点点尝试和错误就产生了非常不错的结果。 注意:从imregionalmax返回的图像并不总是只有单个像素设置为1(以表示最大值)。输出图像通常包含像素簇,因为输入图像中的相邻像素可以具有相等的值,因此都被视为最大值。在上面的代码中,我还用imdilate了这些点,以使其更易于在图像中看到,这使以最大值为中心的像素簇更大。如果要将像素簇减少为单个像素,则应删除散光步骤并以其他方式修改图像(向结果中添加噪点或对其进行过滤,然后找到新的最大值,等等)。 更多&回答... |
![]() |
![]() |