【问题标题】:Detecting thick line clusters and measuring gradient检测粗线簇和测量梯度
【发布时间】:2014-06-21 11:00:08
【问题描述】:

我在这里的第一篇文章 =) 我在 MATLAB 中遇到了一个看似简单的计算问题。 我有一个 0 和 1 的 1000x1000 矩阵。 1 聚集在矩阵对角线上的粗线中,我需要测量这些线簇的梯度。 (从 SW 到 NE 的粗白线)。 到目前为止,我所做的是在每个集群上放置一个标尺并提取线条的点。然而,这不是一个解决方案,因为我有 2000 个矩阵要分析。

阅读渐变 -

问题:

  • 我无法拟合渐变,因为有多个线簇。
  • 我尝试使用 imclose 去除杂散点,但它对我没有帮助 隔离每个集群
  • 我尝试使用边缘检测和霍夫 转换,但它们都不能帮助我隔离集群。

提前非常感谢。如果我的问题不清楚,请告诉我 =)

【问题讨论】:

  • 嘿。我会的,但我不被允许这样做。 dropbox.com/s/qpmdq8vz0zfjuon/control.jpg如果你不介意的话,这个链接里有一个矩阵的例子。
  • 编辑了您的问题。所以我仍然不清楚gradient of line clusters。好吧,是这些星团的斜率吗?
  • 谢谢。你真棒。关于渐变,我会拿一把尺子把它作为最适合的线放在图片中厚厚的白色簇之一。从那里我会画一条线,并得到这条线的渐变。我已经编辑了我在 Dropbox 上上传的图片,如果你再次点击上面的链接,你会明白我的意思
  • 那么,参考最新上传的图片,您想要图像中每个簇的梯度还是想要一个梯度值,就像所有簇梯度的平均值一样?那么,对于上传的图像,您想要四个梯度值还是只需要一个梯度平均值?
  • 如果我能得到一定的误差估计,平均值就可以了。但是获得所有 4 个渐变将是最好的。

标签: matlab image-processing matrix gradient cluster-analysis


【解决方案1】:

代码

%%// Select approach
%%//   1. Gradient values for all clusters
%%//   2. One dominant gradient value for one image
approach_id = 1;

%%// Threshold to the number of pixels that a blob must have
%%// to be declared as a cluster
thresh = 850;

%%// Image scaling factor
img_scale = 0.2; %%// 0.2 seemed to work for the sample

img = imread(image_filenpath);
bw1 = im2bw(img,0.3); %%// 0.3 as threshold-level worked for sample image
bw2 = medfilt2(bw1,[5 5]); %%// 5x5 as denoising window worked

[L, num] = bwlabel(bw2, 8);
counts = sum(bsxfun(@eq,L(:),1:num));


switch approach_id

    case 1
        count1 = 1;
        for k = 1:num
            if counts(k)>thresh
                bw5 = imresize(L==k,img_scale);
                gradient1(count1) = gradval(bw5);
                count1 = count1+1;
            end
        end

    case 2
        bw4 = false(size(bw1));
        for k = 1:num
            if counts(k)>thresh
                bw4 = bw4 | L==k;
            end
        end
        %%// At this point we have a cleaned-up binary image of the input
        bw5 = imresize(bw4,img_scale);
        gradient1 = gradval(bw5);

end

%%// gradient1 is what you need

关联函数

function gradient_value = gradval(BW)

angles = 45:-1:0;

for iter = 1:numel(angles)
    BWr = imrotate(BW,angles(iter));
    t1(iter) = max(sum(BWr,1));
end
[~,ind] = max(t1);
gradient_value = tand(90 - angles(ind));

return;

输出样本图像的聚类梯度值

gradient1 =

    1.6643    1.9626    2.0503    2.0503

请注意,集群是根据 MA​​TLAB 中使用的列优先索引排序的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-02
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 2019-03-20
    相关资源
    最近更新 更多