- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个关于超像素聚类的家庭作业,我遇到了一些困难。我被允许使用 VLFeat 库来仅查找超像素。
找到超像素后,我为每个具有值的超像素定义了一个特征向量; [(超像素中所有像素的平均“R”值)(超像素中所有像素的平均“G”值)(超像素中所有像素的平均“B”值)(超像素中所有像素的平均“色调”值超像素)(超像素中所有像素的平均“饱和度”值)(超像素中所有像素的平均“值”值)]。
之后,我将特征向量和聚类编号发送到内置的 kmeans 函数中以聚类超像素。
function [] = segmentIt (impath, clusNum)
%run vlfeat tools%
run ('vlfeat/toolbox/vl_setup');
%read input image%
image = imread (impath);
imDouble = im2double (image);
%save image W and H%
IH = size (image, 1);
IW = size (image, 2);
%convert input image to single%
imSingle = im2single (image);
%get superpixel data%
superPixels = vl_slic (imSingle, 80, 1);
%how many superpixel do we have?%
SPNUM = size (unique (superPixels), 1);
%changing color space for feature vector%
imHSV = rgb2hsv (image);
%create feature vector with [averageR averageG averageB averageH averageS averageV]%
FEATURE = zeros (SPNUM, 6);
for i=0:SPNUM-1
K = find (superPixels == i);
L = zeros (size(K,1), 2);
L(:,1) = ceil (K(:,1) ./ IW);
L(:,2) = mod(K(:,1), IW) + 1;
intensityTotalR = 0;
intensityTotalG = 0;
intensityTotalB = 0;
vTotal = 0;
sTotal = 0;
hTotal = 0;
for j = 1 : size (L, 1)
intensityTotalR = intensityTotalR + ( imDouble (L(j,1), L(j,2), 1));
intensityTotalG = intensityTotalG + ( imDouble (L(j,1), L(j,2), 2));
intensityTotalB = intensityTotalB + ( imDouble (L(j,1), L(j,2), 3));
vTotal = vTotal + imHSV (L(j,1), L(j,2), 3);
sTotal = sTotal + imHSV (L(j,1), L(j,2), 2);
hTotal = hTotal + imHSV (L(j,1), L(j,2), 1);
end
FEATURE(i+1,:) = [intensityTotalR/size(L,1) intensityTotalG/size(L,1) intensityTotalB/size(L,1) vTotal/size(L,1) sTotal/size(L,1) hTotal/size(L,1)];
end
RESULT = kmeans (FEATURE, clusNum);
newIMAGE = zeros(IH, IW, 3);
colorMultiplier = 1/(clusNum+5);
for i=1:clusNum
K = find (RESULT == i);
for j = 1: size (K,1)
L = find (superPixels == K(j,1));
S = zeros (size(L,1), 2);
S(:,1) = ceil (L(:,1) ./ IW);
S(:,2) = ceil (mod (L(:,1), IW)) + 1;
for z = 1:size(S,1)
newIMAGE (S(z,1), S(z,2), 1) = colorMultiplier * i;
newIMAGE (S(z,1), S(z,2), 2) = colorMultiplier * i;
newIMAGE (S(z,1), S(z,2), 3) = 1;
end
end
end
imshow (newIMAGE)
end
运行我的函数后,生成的图像看起来不太好。知道我的代码中缺少什么吗?
结果图片:
编辑
好吧,这真的很奇怪。我重新为我的超像素着色,这就是我得到的。
EDIT-2
我根据 lennon310
所说的内容编辑了我的代码。哇哦。问题是我使用 find() 函数的方式。
这是簇数等于5时的结果。
从现在开始,我将尝试升级我的特征向量以获得更好的结果。谢谢 lennon310
最佳答案
我觉得代码不错。 colorMultiplier * i
作为小于 1 的值,imshow
应该没问题,但仔细检查 imagesc
以观察差异,尽管可能没有视觉差异。
不看你的形象,很难指出原因。您如何为聚类结果定义“好”?聚类方法对特征密度、大小和您使用的指标非常敏感。我总是喜欢用 this image展示不同的聚类算法如何导致剧烈的分割结果(不幸的是,示例中没有 k-means)。如果 k-means 的分割与您的预期相去甚远,您可能只需要尝试其他方法。
编辑
如果您使用的是 k-means,也许您可以在完全实现之前减少该功能。例如,您可以只使用 RGB 空间功能,并通过在 kmeans 中将 'Replicates'
设置为较小的数字来减少迭代次数,在继续下一步之前观察分割结果。
给定超像素,你能恢复原始图像吗?如果是,您可以尝试通过 reshape
方法查看 RESULT
的图像。这可以在您最终在 newIMAGE
kmeans
是否正常工作
EDIT2
改变
K = find (superPixels == i);
L = zeros (size(K,1), 2);
L(:,1) = ceil (K(:,1) ./ IW);
L(:,2) = mod(K(:,1), IW) + 1;
到
[K1,K2] = find (superPixels == i);
L = zeros (length(K1), 2);
L(:,1) = K1;
L(:,2) = K2;
关于matlab - 超像素聚类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21006428/
在C#中,我可以通过base关键字访问基类,在java中,我可以通过super关键字访问它。在delphi中如何做到这一点?假设我有以下代码: type TForm3 = class(TF
在这件事上我已经把头撞到墙上好几次了。所以我希望在正确的方向上得到一点帮助。 我有一张 table ,上面有订单,一张 table 上有火车,一张 table 上有航类,一张 table 上有巴士。每
在 Python 中,假设我有以下代码: class SuperClass(object): def __init__(self, x): self.x = x
我希望这个 subview 扩展到它的父 View 之外,但是父 View 的边框正在切入 subview 。有没有办法防止这种情况? class TheView : UIView { let
我有一个标准的高斯函数,看起来像这样: def gauss_fnc(x, amp, cen, sigma): return amp * np.exp(-(x - cen) ** 2 / (2
例如,我有下一个类,带有有界类型参数: public class ItemContainer { void addItems(List items); } 在另一个带有参数的类中使用: pub
如何将此设置转换为命令? 结果如下: // Manual Compression (see the image above) Compressed Size: 12,647,451 bytes //
请建议在应用继承时如何使用@Wither/@With。 我有一个抽象类Parent和具体的Child。 Child 应该是不可变的。将 @Wither 放在两者上会给我两个错误: 构造函数 Child
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在尝试向服务器(虚拟托管)发出 HTTP2 请求,该服务器根据主机 header 值 (SNI) 提供 SSL 证书。 # conn = hyper.HTTP20Connection('h
我有一个应用程序,必须将大约 1300 万行、大约 10 个平均长度的字符串插入到嵌入式 HSQLDB 中。我一直在调整一些东西(批量大小、单线程/多线程、缓存/非缓存表、MVCC 事务、log_si
我想定义一个函数f(x, t::Type)根据 isa(x, t) 是否执行不同的行为.假设我想调用b1(x)如果是,b2(x)除此以外。 我知道我可以像这样在运行时进行动态检查: function
我正在使用 Hyper-V WMI Provider在 Hyper-V 中导入虚拟机,特别是使用 ImportVirtualSystemEx Msvm_VirtualSystemManagementS
这几个星期以来一直困扰着我,我没有结束对它的研究,因为我目前重载并且它让我落后于第一年的 CS (opengl) 大学类(class),这首先让我研究了这个:如何只用一个 for 循环绘制立方体的所有
我正在我的计算机(操作系统:Windows 8)上开发一个 WP8 应用程序。我需要安装一个 VM 才能拥有 linux。同时我需要使用我的 Windows Phone 模拟器。 我下载了 VMWar
我是一名优秀的程序员,十分优秀!