Octave 在倍频程的边上绘制梯度向量场

Octave 在倍频程的边上绘制梯度向量场,octave,Octave,我想计算边缘的梯度,并将其绘制为八度向量,叠加到现有图像上 我应用了Sobel操作符来获取边。向量似乎很好。但是我想尽量减少我的代码。以较少的步骤达到相同的效果 我在这里放了一些代码,以便更清楚。提前感谢你的帮助 ########################################################################### # # Get Panda picture # ###########################################

我想计算边缘的梯度,并将其绘制为八度向量,叠加到现有图像上

我应用了Sobel操作符来获取边。向量似乎很好。但是我想尽量减少我的代码。以较少的步骤达到相同的效果

我在这里放了一些代码,以便更清楚。提前感谢你的帮助

###########################################################################
#
# Get Panda picture
#
###########################################################################
C = imread ("C:\\Users\\Elizabeth Judith\\Desktop\\cesar\\panda.png");

###########################################################################
#
# Transform Panda picture from Colors to Gray
#
###########################################################################
G = 0.3*C(:,:,1) + 0.6*C(:,:,2) + 0.1*C(:,:,3);
imwrite(G,"C:\\Users\\Elizabeth Judith\\Desktop\\cesar\\panda_gray.png");

###########################################################################
#
# Gradient of Sobel
#
###########################################################################
Edge = edge(G,"sobel");
[gx,gy] = gradient(double(Edge));

indices = find(abs(gx)==0.5);
indices = indices(1:2:end); # To delete arrows
gx(indices) = NaN; 

indices = find(abs(gx)==0.5);
indices = indices(1:2:end); # To delete arrows
gx(indices) = NaN;

indices = find(abs(gx)==0.5);
indices = indices(1:2:end); # To delete arrows
gx(indices) = NaN;

indices = find(abs(gy)==0.5);
indices = indices(1:2:end); # To delete arrows
gy(indices) = NaN; 

indices = find(abs(gy)==0.5);
indices = indices(1:2:end); # To delete arrows
gy(indices) = NaN; 

indices = find(abs(gy)==0.5);
indices = indices(1:2:end); # To delete arrows
gy(indices) = NaN; 

###########################################################################
#
# plot gradient vectors over image
#
###########################################################################
figure;
imshow(G, []);
hold on;

###########################################################################
#
# Quiver of the gradient
#
###########################################################################
h1 = quiver(abs(gx),abs(gy));

###########################################################################
#
# To scale quiver arrows
#
###########################################################################
set(h1,'AutoScale','on', 'AutoScaleFactor', 15);

还有另一种方法可以减少抖动曲线图的箭头数量:

问题是它会缩小图像的比例,因为它占用了一半的梯度信息。因此,您可能也可以缩放背景图像,并以较少的步骤获得类似的结果


致以最诚挚的问候

那么,请澄清,您的代码对您有用吗?它能产生正确的输出吗?那么,您是否在寻求一些具体的改进?速度如果不是,为什么要少走几步?如果它们做相同的工作,那么清晰的代码通常比紧凑的代码好,除非您有其他目标。为了提高速度,您可以尝试运行代码探查器,查看它在哪里花费了大部分时间。此外,最好链接一个示例图像,以便其他人可以看到您开始使用的内容。代码可以正常工作,并生成正确的输出。但我删除箭头的方式在我看来很复杂。我想知道是否有办法使它更简单。另一方面,我还不允许在我的帖子中嵌入图片,所以我加入了一个链接(合成图片)。我明白了,这个解决方案只需很少的步骤。但正如你提到的,它会缩小我的矢量图像。不过,我也可以缩小背景图像的比例,以更低的分辨率获得类似的结果。如果你不在乎最终的解决方案,这可能是个不错的选择。
quiver(gx(1:2:end,1:2:end),gy(1:2:end,1:2:end))