PDA

查看完整版本 : 如何找到图像中最密集的区域?


poster
2019-12-10, 20:30
考虑像黑白图像此 (http://img13.imageshack.us/img13/7401/10416827.jpg)

https://i.stack.imgur.com/HNyUF.jpg

我要做的是找到白点最密集的区域。在这种情况下,有20-21个这样的密集区域(即,点的簇构成一个密集区域)。

谁能给我任何有关如何实现的提示?



回答:

如果可以访问“ 图像处理工具箱” (https://www.mathworks.com/help/images/) ,则可以利用其中包含的许多过滤和形态学操作。使用函数imfilter (https://www.mathworks.com/help/images/ref/imfilter.html) , imclose (https://www.mathworks.com/help/images/ref/imclose.html)和imregionalmax (https://www.mathworks.com/help/images/ref/imregionalmax.html) ,这是解决问题的一种方法:

% 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'); 这是上面的代码创建的图像:

https://i.stack.imgur.com/4JSRd.jpg (https://i.stack.imgur.com/4JSRd.jpg)

为了让事情看起来不错,我只是一直在尝试为高斯滤波器(使用创建的参数的几个不同的组合fspecial (https://www.mathworks.com/help/images/ref/fspecial.html) )和结构元素(使用创建strel (https://www.mathworks.com/help/images/ref/strel-class.html) )。但是,一点点尝试和错误就产生了非常不错的结果。

注意:从imregionalmax (https://www.mathworks.com/help/images/ref/imregionalmax.html)返回的图像并不总是只有单个像素设置为1(以表示最大值)。输出图像通常包含像素簇,因为输入图像中的相邻像素可以具有相等的值,因此都被视为最大值。在上面的代码中,我还用imdilate (https://www.mathworks.com/help/images/ref/imdilate.html)了这些点,以使其更易于在图像中看到,这使以最大值为中心的像素簇更大。如果要将像素簇减少为单个像素,则应删除散光步骤并以其他方式修改图像(向结果中添加噪点或对其进行过滤,然后找到新的最大值,等等)。



更多&回答... (https://stackoverflow.com/questions/2001475)