【发布时间】:2017-09-21 11:49:43
【问题描述】:
Gnoivce 和 Hartmut 对这段代码帮助很大,但运行起来需要一段时间。 bar 命令中的 CData 属性似乎没有在我使用的 Octave 4.0-4.2.1 版本中实现。解决此问题的方法是单独绘制所有单个条并为每个单独的条设置单独的颜色。人们帮助我,让我走到了这一步,但情节需要 5 分钟 显示有没有人知道加快速度的方法?
以下代码运行: 下面使用的 marbles.jpg 图像文件:
clear all,clf reset,tic,clc
rgbImage = imread('/tmp/marbles.jpg');
hsvImage = rgb2hsv(rgbImage); % Convert the image to HSV space
hPlane = 360.*hsvImage(:, :, 1); % Get the hue plane scaled from 0 to 360
binEdges = 0:360; %# Edges of histogram bins
N = histc(hPlane(:),binEdges); %# Bin the pixel hues from above
C = colormap(hsv(360)); %# create an HSV color map with 360 points
stepsize = 1; % stepsize 1 runs for a while...
for n=binEdges(2:stepsize:end) %# Plot the histogram, one bar each
if (n==1), hold on, end
h=bar(n,N(n));
set(h,'FaceColor',C(n,:)); %# set the bar color individually
end
axis([0 360 0 max(N)]); %# Change the axes limits
set(gca,'Color','k'); %# Change the axes background color
set(gcf,'Pos',[50 400 560 200]); %# Change the figure size
xlabel('HSV hue (in degrees)'); %# Add an x label
ylabel('Bin counts'); %# Add a y label
fprintf('\nfinally Done-elapsed time -%4.4fsec- or -%4.4fmins- or -%4.4fhours-\n',toc,toc/60,toc/3600);
查看原问题original question
【问题讨论】:
-
您是否检查过代码的哪一部分花费了这么长时间?是循环吗?
-
@gnovice 是的
stepsize = 1; % stepsize 1 runs for a while...会导致时间增加,如果stepsize is set to 10更快,但会在条形之间留下空白空间。 -
为什么不生成图像而不是条形图?
-
@Andy 我愿意尝试任何东西,但我是否还需要循环通过导致速度变慢的 For 循环?还是我错过了什么?
-
@RickT 这两个答案中是否缺少某些内容?如果您不接受其中之一,您应该评论他们为什么不回答您的问题