【问题标题】:How to use subclust in matlabmatlab中子集的使用方法
【发布时间】:2014-11-09 10:22:50
【问题描述】:

我有一个问题:如何在 matlab 中使用 subclust() 函数和加载了 imread() 函数的图像?我有代码

rgb = imread('6_rubets.jpg');
gr = rgb2gray(rgb);
[c, s] = subclust(gr, 0.3);

我需要获取该图像上的聚类中心,结果我需要对图像上的像素进行分类。 但我有错误:

Error using  .* 
Integers can only be combined with integers of the same class, or scalar doubles.

Error in subclust (line 169)
    dx = (thePoint - X) .* new_accumMultp;

Error in lab_1 (line 3)
[c, s] = subclust(gr, 0.3);

我需要做什么才能找到分类中心?

提前致谢

【问题讨论】:

  • 你能上传图片吗?还有,你的意思是说整个help page都没有用?
  • @Dev-iL 我可以上传图片,但它是来自互联网的随机图片。填写我的代码rgb = imread('test.jpg'); gr = rgb2gray(rgb); [c, s] = subclust(gr, 0.3); imshow(gr);,但我有错误Error using .* Integers can only be combined with integers of the same class, or scalar doubles. Error in subclust (line 169) dx = (thePoint - X) .* new_accumMultp; Error in lab_1 (line 3) [c, s] = subclust(gr, 0.3);
  • 而且我以前从未使用过matlab...对不起,如果我的问题看起来很愚蠢。
  • 首先,请编辑问题以包含代码,而不是将其放在评论中。接下来,在提及该功能之前解释您要做什么。也许还有另一种不需要它的解决方案。
  • 我无法测试它,但如果你像这样将 gr 转换为 single 会怎样:gr = single(rgb2gray(rgb));看起来 subclust 不喜欢 uint8 类型的数据,就像您的图像一样。

标签: image matlab image-processing cluster-analysis


【解决方案1】:

这不起作用的原因是subclust 不支持uint8 的输入(或我认为的任何整数......)。我怀疑在内部,subclust 正在创建double 类型的数组/矩阵,然后当它尝试对您的图像对这些数组/矩阵进行操作时,您会收到该错误。正如错误提示的那样,不允许混合不同变量类型的操作。

因此,请尝试将您的图像投射到double,然后再次运行代码。这不会改变实际数字,但会改变变量的类别 (double)。我这样做了,它对我有用。例如,我使用了cameraman.tif,它是 MATLAB 系统路径的一部分:

im = imread('cameraman.tif'); %// Image already grayscale
[c,s] = subclust(double(im), 0.3);

在你的情况下,你必须这样做:

rgb = imread('6_rubets.jpg');
gr = rgb2gray(rgb);
[c, s] = subclust(double(gr), 0.3);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-27
    • 2013-10-11
    相关资源
    最近更新 更多