【问题标题】:Figure window showing up matlab显示matlab的图形窗口
【发布时间】:2014-05-06 14:11:54
【问题描述】:

我编写了这段代码来帮助我比较不同的图像直方图,但是当我运行它时,我会弹出一个图形窗口。我在编写 imshow 的代码中看不到任何地方,我真的很困惑。谁能明白为什么?谢谢

%ensure we start with an empty workspace
clear

myPath= 'C:\coursework\'; %#'
number_of_desired_results = 5; %top n results to return

images_path = strcat(myPath, 'fruitnveg');
images_file_names = dir(fullfile(images_path, '*.png'));
images = cell(length(images_file_names), 3);
number_of_images = length(images);

%textures contruction
%loop through all textures and store them
disp('Starting construction of search domain...');
for i = 1:length(images)
    image = strcat(images_path, '\', images_file_names(i).name); %#'

    %store image object of image
    images{i, 1} = imread(image);
    %store histogram of image
    images{i, 2} = imhist(rgb2ind(images{i, 1}, colormap(colorcube(256))));
    %store name of image
    images{i, 3} = images_file_names(i).name;
    disp(strcat({'Loaded image '}, num2str(i)));
end
disp('Construction of search domain done');

%load the three example images

RGB1 = imread('C:\coursework\examples\salmon.jpg');
X1 = rgb2ind(RGB1,colormap(colorcube(256)));
example1 = imhist(X1);

RGB2 = imread('C:\coursework\examples\eggs.jpg');
X2 = rgb2ind(RGB2,colormap(colorcube(256)));
example2 = imhist(X2);

RGB3 = imread('C:\coursework\examples\steak.jpg');
X3 = rgb2ind(RGB3,colormap(colorcube(256)));
example3 = imhist(X3);

disp('three examples loaded');

disp('compare examples to loaded fruit images');

results = cell(length(images), 2);

results2 = cell(length(images), 2);

results3 = cell(length(images), 2);

for i = 1:length(images)
    results{i,1} = images{i,3};
    results{i,2} = hi(example1,images{i, 2});
end

results = flipdim(sortrows(results,2),1);

for i = 1:length(images)
    results2{i,1} = images{i,3};
    results2{i,2} = hi(example2,images{i, 2});
end

results2 = flipdim(sortrows(results2,2),1);

for i = 1:length(images)
    results3{i,1} = images{i,3};
    results3{i,2} = hi(example3,images{i, 2});
end

results3 = flipdim(sortrows(results3,2),1);

【问题讨论】:

  • 您是否尝试放置一些断点并调试您的代码?
  • 它来自这段代码,但我真的不明白为什么!图片{i, 2} = imhist(rgb2ind(images{i, 1}, colormap(colorcube(256))));

标签: image matlab


【解决方案1】:

Etienne 的回答是正确的,为什么你得到一个数字,但我想补充一点,colormap 在这段代码中是不必要的:

images{i, 2} = imhist(rgb2ind(images{i, 1}, colormap(colorcube(256))));

你只需要:

images{i, 2} = imhist(rgb2ind(images{i, 1}, colorcube(256)));

rgb2ind 的第二个输入应该是颜色图,是的。但是colorcube 的输出已经是一个颜色图了。除非您有一个现有的图形,并且您想要设置它的颜色图或检索它当前使用的颜色图,否则实际函数 colormap 不是必需的。

除了打开一个不必要的图形之外,现有代码的输出不会出错,因为我认为在这种情况下colormap 只会将它作为输入参数给出的颜色图作为输出参数传递。例如,如果您想将当前图形颜色图设置为内置之一,则返回实际的颜色图:

cmap = colormap('bone');

【讨论】:

    【解决方案2】:

    colormap 函数设置当前图形的颜色图,如果没有创建图形。

    imhist 的第二个参数应该是直方图中使用的 bin 数量,而不是颜色图。

    【讨论】:

    • 有没有办法抑制输出?
    • 如果你看看:edit colormap,我认为没有办法。
    • 我把“全部关闭”放在脚本的末尾,效果很好。感谢您的帮助
    【解决方案3】:

    在 Matlab 调试器中运行您的代码,逐行执行,查看图形窗口何时弹出。这会告诉你是什么创造了它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多