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
在matlab中使用subplot命令绘制图形,但功能不同_Matlab_Image Processing - Fatal编程技术网

在matlab中使用subplot命令绘制图形,但功能不同

在matlab中使用subplot命令绘制图形,但功能不同,matlab,image-processing,Matlab,Image Processing,我用的是matlab函数。此功能使用相同图像的片段。但最后,我没有把这些碎片组合起来。我只能显示不同的数字。如何重新加入此图像?(我看过Mathematica使用的'ImageAssembly'命令,也许matlab有这样的函数。)如果没有一个函数,我想这个和平可以在subplot命令下显示,但问题是我必须在函数中打开subplot,每次调用函数时,都会打开不同的子Plot。我只想打开一个子地块。例如,我有一个如下的函数 function[] =seperate(I,n,m) I1=I(1:m/

我用的是matlab函数。此功能使用相同图像的片段。但最后,我没有把这些碎片组合起来。我只能显示不同的数字。如何重新加入此图像?(我看过Mathematica使用的'ImageAssembly'命令,也许matlab有这样的函数。)如果没有一个函数,我想这个和平可以在subplot命令下显示,但问题是我必须在函数中打开subplot,每次调用函数时,都会打开不同的子Plot。我只想打开一个子地块。例如,我有一个如下的函数

function[] =seperate(I,n,m)
I1=I(1:m/2,1:n/2);
I2=I(1:m/2,n/2+1:n);
I3=I(m/2+1:m,1:n/2);
I4=I(m/2+1:m,n/2+1:n);
subplot(2,4,1)   %for eight image
imshow(I1);
subplot(2,4,2)
imshow(I2);
subplot(2,4,3)
imshow(I3);
subplot(2,4,4)
imshow(I4);
end
有一个实际的程序

img=imread('any_image.jpg');
gray=rgb2gray(img);
[n,m] = size(gray);
seperate(gray,n,m);
img_2=imread('any_image_2');
gray_2=rgb2gray(img_2);
[n1,m1]=size(gray_2)
seperate(gray_2,n1,m1);
正如你所看到的,这个“分离”功能将4个相等的和平分离成一个图像。当您在两个不同的图像中使用此函数时,您有两个不同的子图。我想要一个副批次。例如,第一个图像和平应放置在“子地块(2,4,1)、子地块(2,4,2)、子地块(2,4,3)、子地块(2,4,4)”,第二个图像和平应放置在“子地块(2,4,5)、子地块(2,4,6)、子地块(2,4,7)、子地块(2,4,8)”。我该怎么做?
我也可以重新加入这些和平,我可以创造一个由前两个和平中的8个和平组成的“一个和平”的新形象吗?谢谢您的帮助。

您的问题陈述得非常详细,初始代码中有错误。但是,由于提供了代码,我运行了代码并设法理解了问题:

您两次调用一个函数(它有一些图形输出),但您希望图形以相同的
图形输出(您使用
子图
这个词太多,有时不合适)

确保函数始终绘制在同一图中的方法是:

  • 将标识符附加到目标图形(我使用了
    标签
    属性,但可以使用其他属性(
    Name
    ) 只要您可以分配唯一标识符)
  • 当函数必须进行图形输出时,它首先搜索 目标数字存在。您可以使用该函数来实现这一点。如果
    yes
    它直接输出到它,如果
    no
    它 创建一个新的
下面是对函数的重写
separate.m

function seperate(I,subset)

    % default subset = 1
    if nargin < 2 ; subset=1 ; end

    % first find if the target figure already exist
    hfig = findobj(0,'Type','figure','Tag','SeparatingFigure') ;
    if isempty(hfig)
        figure('Tag','SeparatingFigure') ; % create a new one
    else
        figure(hfig) ; % just make the existing figure active
    end

    % now split the image in 4 pieces
    [m,n] = size(I);
    Isplit{1} = I(1:m/2,1:n/2) ;
    Isplit{2} = I(1:m/2,n/2+1:n);
    Isplit{3} = I(m/2+1:m,1:n/2);
    Isplit{4} = I(m/2+1:m,n/2+1:n);

    % now display to the proper set of subplots
    % "subpos" store the index of the 4 subplot to use for 1 subset
    subpos = [1 2 5 6 ; ... %subset "1" will plot in subplot [1 2 5 6]
              3 4 7 8] ;    %subset "2" will plot in subplot [3 4 7 8]
    for k=1:4
        subplot(2,4,subpos(subset,k))   
        imshow(Isplit{k});
    end
end

你扔给它的任何新图像都将简单地替换旧图像(仍在同一个图中):


只需将两张图像分别传递给
并添加更多
子批次
呼叫…非常感谢。这正是我需要的。我们也可以在这个过程结束后,对这些单独的和平进行一次和平吗?好吧,你已经手动分割了图像,你可以将这些片段重新连接在一起。类似于
Ifull=[Isplit{1},Isplit{2};Isplit{3},Isplit{4}]
img1=imread('coins.png');
seperate(img1,1);

img2=imread('peppers.png');
seperate(img2,2);
% replace the first subset with another image
img3=imread('football.jpg');
seperate(img3,1);