我怎样才能找到最密集区域的图像? [英] How can I find the most dense regions in an image?

查看:357
本文介绍了我怎样才能找到最密集区域的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个黑白图像像

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

What I am trying to do is to find the region where the white points are most dense. In this case there are 20-21 such dense regions (i.e. the clusters of points makes a dense region).

谁能给我如何能做到这一点的任何提示?

Can anyone give me any hint on how this can be achieved?

推荐答案

如果您访问图片处理工具箱,你可以采取一些含有滤波和形态学的优势。这里是你可以接近你的问题的一种方法,使用函数 IMFILTER IMCLOSE 和的 IMREGIONALMAX

If you have access to the Image Processing Toolbox, you can take advantage of a number of filtering and morphological operations it contains. Here's one way you could approach your problem, using the functions IMFILTER, IMCLOSE, and 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');

和这里的上述code创建映像:

And here's the image the above code creates:

要得到的东西看起来不错,我只是不停地尝试一些不同的组合的参数高斯滤波器(创建使用的 FSPECIAL )和结构元素(使用的 STREL )。然而,试错的那一点点给了一个很不错的结果。

To get things to look good I just kept trying a few different combinations for the parameters for the Gaussian filter (created using FSPECIAL) and the structuring element (created using STREL). However, that little bit of trial and error gave a very nice result.

注意:图片来自 IMREGIONALMAX返回的不总是具有只是单一的像素设置为1(以指示最大值)。输出图像经常包含簇的像素,因为在输入图像的相邻像素可以具有相同的值,并因此既算作最大值。在code上面我也散瞳这些点 IMDI​​LATE 只是为了让他们更容易地看到图像,这使得集中在最大值像素的更大的群集。如果你想减少像素的群集到单个像素,应删除扩张的步骤和修改以其他方式(增加噪声的结果,或者进行过滤,然后找到新的最大值等)的图像。

NOTE: The image returned from IMREGIONALMAX doesn't always have just single pixels set to 1 (to indicate a maxima). The output image often contains clusters of pixels because neighboring pixels in the input image can have equal values, and are therefore both counted as maxima. In the code above I also dilated these points with IMDILATE just to make them easier to see in the image, which makes an even bigger cluster of pixels centered on the maxima. If you want to reduce the cluster of pixels to a single pixel, you should remove the dilation step and modify the image in other ways (add noise to the result or filter it, then find the new maxima, etc.).

这篇关于我怎样才能找到最密集区域的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆