how to do Image translation

3 次查看(过去 30 天)
Naomi Penelope
Naomi Penelope 2021-9-1
编辑: DGM 2021-9-2
Translate image RB2 in the amounts of deltax=size(RB2,2)/4, deltay=size(RB2,1)/4 continuously 4 times, i.e, at the first time, RB2 is translated deltax and deltay, at the second time, RB2 is translated 2deltax and 2deltay, etc. Practice: size(RB2,1) returns the first dimension of RB2, i.e., the number of rows in RB2. size(RB2,2) returns the number of columns in RB2.
* Add all translated images together to form a summation image (same “floating” data type issue!)
* Output 4 individual translated images and the summation image that should be presented in a displayable format.
* Note that since we consider an image is a 2D periodic function, the fourth time translation should produce the original image. “mod” command or “circshift” command may help you simplify processing.

回答(1 个)

DGM
DGM 2021-9-2
编辑:DGM 2021-9-2
blef.
A = im2double(imread('cameraman.tif'));
s = imsize(A,3); % nonstandard; see attached file
B = zeros([s 4]);
for f = 1:4
B(:,:,:,f) = circshift(A,round(s(1:2)*f/4));
end
subplot(1,2,1)
montage(B)
% summing the images will push values out of standard data ranges for no good reason
% use the mean to keep data sane and usable/writeable.
C = mean(B,4);
subplot(1,2,2)
imshow(C)
Note that the assignment describes the image as a periodic function and asks you to circshift by size/4 to demonstrate a full cycle of the image. This doesn't work unless the image geometry is integer-divisible by 4. Also, as the note mentions, there's no good reason to add the images instead of using the mean. The sum of the images will be outside of standard data range and will need to be renormalized for many tasks (e.g. writing the image to a file). Normalizing the sum of floating point images is the same as taking the mean. Just take the mean.
I don't know what anyone is supposed to learn from this other than to question everything.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by