MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何找到图像中最密集的区域? (https://www.labfans.com/bbs/showthread.php?t=23033)

poster 2019-12-10 20:30

如何找到图像中最密集的区域?
 
考虑像黑白图像[URL="http://img13.imageshack.us/img13/7401/10416827.jpg"]此[/URL]

[IMG]https://i.stack.imgur.com/HNyUF.jpg[/IMG]

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

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



[B]回答:[/B]

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

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

[URL="https://i.stack.imgur.com/4JSRd.jpg"][IMG]https://i.stack.imgur.com/4JSRd.jpg[/IMG][/URL]

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

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



[url=https://stackoverflow.com/questions/2001475]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 05:00

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.