Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 粗线簇的检测与梯度测量_Matlab_Image Processing_Matrix_Gradient_Cluster Analysis - Fatal编程技术网

Matlab 粗线簇的检测与梯度测量

Matlab 粗线簇的检测与梯度测量,matlab,image-processing,matrix,gradient,cluster-analysis,Matlab,Image Processing,Matrix,Gradient,Cluster Analysis,我在这里的第一篇帖子=) 我在MATLAB中遇到了一个看似简单的计算问题。 我有一个由0和1组成的1000x1000矩阵。1在矩阵的对角线上聚集成一条粗线,我需要测量这些线簇的梯度。(从西南到东北的粗白线)。 到目前为止,我所做的是在每个簇上放置一把尺子并提取线的点。然而,这不是一个解决方案,因为我有2000个矩阵要分析 阅读梯度- 问题: 我无法拟合渐变,因为有多个线簇 我试着用imclose来删除这些零散的点,但它对我没有帮助 隔离每个群集 我尝试使用边缘检测和Hough 转换,但它们

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

阅读梯度-

问题:

  • 我无法拟合渐变,因为有多个线簇
  • 我试着用imclose来删除这些零散的点,但它对我没有帮助 隔离每个群集
  • 我尝试使用边缘检测和Hough 转换,但它们都不能帮助我分离集群
非常感谢。如果我的问题不清楚,一定要告诉我=)

代码

%%// 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
gradient1 =

    1.6643    1.9626    2.0503    2.0503
相关功能

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;
输出样本图像的聚类梯度值

%%// 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
gradient1 =

    1.6643    1.9626    2.0503    2.0503

请注意,集群是根据MATLAB中使用的列主索引排序的。

Hey。我本来会这样做的,但我不被允许这样做。如果你不介意,这个链接中有一个矩阵的例子。编辑你的问题。所以我仍然不清楚线簇的梯度。好的,这是这些簇的斜率吗?谢谢。你太棒了。关于梯度,我会拿一把尺子,把它作为一条最合适的线放在图片中一个厚厚的白色簇上。从那里我画一条线,得到这条线的梯度。我已经编辑了我在dropbox上上传的图片,如果你再次点击上面的链接,你会看到我的意思。那么,参考最新上传的图片,你想要图像中每个簇的梯度还是像所有簇梯度的平均值一样的一个梯度值?那么,对于上传的图像,你想要四个梯度值还是一个梯度的平均值?如果我能得到一定的误差估计,平均值就可以了。但获得所有4个渐变将是最好的。