我有8张图片,我想以如下所示的比例空间格式显示它们原始图像的高度和宽度为256然后在原始图像的右侧,在每个级别上,大小都减小2像这里一样,图像的高度和宽度是256在原始图像的右侧,高度和宽度为128、64、32、16、8、4、2。
我有所有的图像在各自的维度我只想知道如何根据下面显示的模式排列图像提前谢谢。

最佳答案

这看起来像是您试图构建一个缩放空间并将结果显示给用户这不是问题请记住,您必须使用for循环来完成这项工作,因为除非复制并粘贴几行代码,否则我看不出您将如何完成这项工作实际上,我将使用一个while循环,我将很快告诉您原因。
在任何情况下,您都需要声明一个输出图像,该图像的行数与原始图像的行数相同,但列数将是原始图像的1.5倍,以适应右侧的图像。
首先,编写代码,将原始图像放在左侧,将一半大小的版本放在右侧一旦你这样做,你就写一个for循环,使用索引把图像放在正确的地方直到你的天平耗尽,你需要跟踪下一个图像开始的位置和下一个图像的结束。请记住,在第一个子采样之后,下一个图像的写入位置的原点将从原始图像的列位置开始,而行正好位于前一个图像的结束位置作为一个例子,让我们使用cameraman.tif图像,它正好是256 x 256,但我将编写代码,以便它适合您想要的任何图像分辨率当我对图像进行子采样时,我将使用MATLAB中的imresize帮助调整图像的大小,并将采样因子指定为0.5以表示子采样为2我之所以使用while循环,是因为我们可以一直循环并调整大小,直到调整大小的图像的某个维度1为止在这种情况下,没有更多的音阶来处理,所以我们可以退出。
像这样的:

%// Read in image and get dimensions
im = imread('cameraman.tif');
[rows,cols] = size(im);

%// Declare output image
out = zeros(rows, round(1.5*cols), 'uint8');
out(:,1:cols) = im; %// Place original image to the left

%// Find first subsampled image, then place in output image
im_resize = imresize(im, 0.5, 'bilinear');
[rows_resize, cols_resize] = size(im_resize);
out(1:rows_resize,cols+1:cols+cols_resize) = im_resize;

%// Keep track of the next row we need to write at
rows_counter = rows_resize + 1;

%// For the rest of the scales...
while (true)
    %// Resize the image
    im_resize = imresize(im_resize, 0.5, 'bilinear');
    %// Get the dimensions
    [rows_resize, cols_resize] = size(im_resize);
    %// Write to the output
    out(rows_counter:rows_counter+rows_resize-1, cols+1:cols+cols_resize) = ...
        im_resize;

    %// Move row counter over for writing the next image
    rows_counter = rows_counter + rows_resize;

    %// If either dimension gives us 1, there are no more scales
    %// to process, so exit.
    if rows_resize == 1 || cols_resize == 1
        break;
    end
end

%// Show the image
figure;
imshow(out);

这是我得到的图像:

10-05 20:59
查看更多