Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 显示matlab的图形窗口_Image_Matlab - Fatal编程技术网

Image 显示matlab的图形窗口

Image 显示matlab的图形窗口,image,matlab,Image,Matlab,我写了这段代码来帮助我比较不同的图像直方图,但是当我运行它时,我会弹出一个图形窗口。我在代码中看不到我写过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, 'fru

我写了这段代码来帮助我比较不同的图像直方图,但是当我运行它时,我会弹出一个图形窗口。我在代码中看不到我写过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);

在Matlab调试器中运行代码,逐行遍历代码,然后查看图形窗口何时弹出。这将告诉您创建它的原因。

如果没有创建任何地物,则
colormap
函数将设置当前地物的colormap


imhist
的第二个参数应该是直方图中使用的箱子数量,而不是彩色地图。

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
只会将作为输入参数提供的colormap作为输出参数传递。例如,如果要将当前地物颜色贴图设置为内置的之一,并返回实际的颜色贴图:

cmap = colormap('bone');

你试过设置一些断点并调试你的代码吗?它来自这段代码,我真的不明白为什么!images{i,2}=imhist(rgb2ind(images{i,1},colormap(colorcube(256)));有没有办法抑制输出?如果你看一下:edit colormap,我认为没有办法。我在脚本末尾加了“close all”(全部关闭),效果很好。谢谢你的帮助