在MATLAB中显示图像比例空间 [英] Display an image scale space in MATLAB

查看:543
本文介绍了在MATLAB中显示图像比例空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有8张图片,我想以下面显示的比例空间格式显示它们。原始图像的高度和宽度为256.然后在原始图像的右侧,每个级别的大小减少2.像这里,图像的高度和宽度是256.在原始图像的右侧,高度和宽度是128 ,64,32,16,8,4,2。

I have 8 images and I want to show them in a scale-space format shown below. The original image height and width is 256. Then on right side of original image, at every level the size is reduced by 2. Like here, image height and width is 256. On the right side of original image, height and width is 128, 64, 32, 16, 8, 4 , 2.

我有各自尺寸的所有图像。我只是想知道如何根据下面显示的模式排列图像。在此先感谢。

I have all the images in their respective dimensions. I just want to know how do I arrange the images according the pattern shown below. Thanks in advance.

推荐答案

这看起来像是在尝试构建一个缩放空间并将结果显示给用户。这不是一个问题。请记住,对于循环,您必须使用执行此操作,因为我看不到您将如何执行此操作,除非您复制并粘贴多行代码。实际上,我将在循环时使用,我会告诉你为什么很快。

This looks like you are trying to build a scale-space and displaying the results to the user. This isn't a problem to do. Bear in mind that you will have to do this with for loops, as I don't see how you will be able to do this unless you copy and paste several lines of code. Actually, I'm going to use a while loop, and I'll tell you why soon.

In无论如何,你需要声明一个输出图像,其行数和原始图像一样多,但是列的原始图像将是 1.5 ,以适应原始图像上的图像。正确。

In any case, you need to declare an output image that has as many rows as the original image, but the columns will be 1.5 times the original image to accommodate for the images on the right.

首先,编写将原始图像放在左侧的代码,以及尺寸为右侧一半的版本。一旦你这样做,你为循环写一个,使用索引将图像放在正确的位置,直到你的标尺用完为止,你需要跟踪下一张图像开始,下一张图像结束。请记住,在第一个二次采样之后写下一个图像的位置的起点将从原始图像的列位置开始,并且该行正好在前一个结束的位置。举个例子,让我们使用 cameraman.tif 图像,这个图像正好是 256 x 256 ,但我会写代码所以它适合您想要的任何图像分辨率。当我对图像进行二次采样时,我将使用 imresize 有助于调整图像大小,我将指定一个 0.5 的采样因子来表示2的子采样。我之所以使用循环,是因为我们可以保持循环并调整的大小,直到调整大小的图像的某个维度为 1 。在这种情况下,没有更多的尺度需要处理,因此我们可以退出。

First, write code that places the original image on the left side, and the version that is half the size on the right. Once you do this, you write a for loop, use indexing to place the images in the right spots until you run out of scales, and you need to keep track of where the next image starts and next image ends. Bear in mind that the origin of where to write the next images after the first subsampled one will start at the column location of the original image, and the row is right where the previous one ends. As an example, let's use the cameraman.tif image that is exactly 256 x 256, but I will write code so that it fits any image resolution you want. When I subsample the image, I will use imresize in MATLAB to help with the resizing of the image, and I'll specify a sampling factor of 0.5 to denote the subsampling by 2. The reason why I would use a while loop instead, is because we can keep looping and resizing until one of the dimensions of the resized image is 1. When this is the case, there are no more scales to process, and so we can exit.

因此:

%// 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);

这是我得到的图像:

这篇关于在MATLAB中显示图像比例空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆