我遇到了一个关于图片的问题。我想将一张图片缩小至原来的四分之一,然后将其重复成一个2x2矩阵。就像这样:
Given an input image:
---------------------
| |
| |
| IMG |
| |
| |
---------------------
Firstly, shrink it to 1/4 of its original size:
-----------
| img |
| |
|---------|
Then concatenate it into a "2x2 array" of the shrunken image:
---------------------
| img | img |
| | |
|---------|---------|
| img | img |
| | |
---------------------
我遇到的问题是我不知道如何将它转换为2x2的数组。有什么建议吗?这次不是作业,只是为了学习目的。以下是我到目前为止尝试过的:
function[newImg] = immultiply(picture)
Image = imread(picture); %// Reads in the picture
[r, c, l] = size(Image); %// Finds the images rows, columns and layers
rows = round(r ./ 2); %// Divides up the rows
columns = round(c ./ 2); %// Divides up the columns
newImg = cat(3,rows,columns,3); %// Creates my image, but just gives me a blank thing
imshow(newImg)
end
我会在进一步的工作中进行更新。谢谢!
repmat
:repmat(img,2,2)
,但那并不是2 x 2
,它更像是沿行和列扩大了两倍的img
。 - Divakarrepmat({img},2,2)
来输出一个大小为2 x 2
的单元数组。 - Divakar