如何将图像插入手机壳

时间:2015-07-06 18:37:20

标签: matlab image-processing 3d photoshop adobe-illustrator

我有一张图片,

enter image description here

我想将它们插入手机壳中,如下所示:

enter image description here

enter image description here

enter image description here

enter image description here

得到这个:

enter image description here

enter image description here

enter image description here

enter image description here

是否可以使用任何图像处理算法来自动执行此过程?

我想有一些想法来实现这个目标

1 个答案:

答案 0 :(得分:3)

修改

以下是impoly的修订版:

% Read images
skull = imread('skull.jpg');
skull_mask = true(size(skull,1),size(skull,2)); % Use mask for overlay

shell = imread('shell2.jpg');
imshow(shell);
hold on;
p_h = impoly;

% Find transformation (either set this manually or find it with something
% like sift)
input_points = [0              size(skull,1); 
                size(skull,2)  size(skull,1); 
                size(skull,2)  0;
                0              0];

base_points = getPosition(p_h);

% Perform transformation
tform = cp2tform(input_points,base_points,'projective');

skull = imtransform(skull, tform, ...
                    'XData', [1 size(shell,2)], ...
                    'YData', [1 size(shell,1)], ...
                    'Size', [size(shell,1) size(shell,2)]);

skull_mask = imtransform(skull_mask, tform, ...
                         'XData', [1 size(shell,2)], ...
                         'YData', [1 size(shell,1)], ...
                         'Size', [size(shell,1) size(shell,2)]);

skull_mask = imerode(skull_mask,strel('disk',2)); % Prevents rough edges

% Overlay images
skull_r = skull(:,:,1);
skull_g = skull(:,:,2);
skull_b = skull(:,:,3);

shell_overlay_r = shell(:,:,1);
shell_overlay_g = shell(:,:,2);
shell_overlay_b = shell(:,:,3);

shell_overlay_r(skull_mask) = skull_r(skull_mask);
shell_overlay_g(skull_mask) = skull_g(skull_mask);
shell_overlay_b(skull_mask) = skull_b(skull_mask);

% Combine into one image
shell_overlay(:,:,1) = shell_overlay_r;
shell_overlay(:,:,2) = shell_overlay_g;
shell_overlay(:,:,3) = shell_overlay_b;

% Show overlay
imshow(shell_overlay);

如果你想为任意输入shell图像提供强大的实现,你需要使用像SIFT这样的东西,我不建议这样做,因为它很难。我建议只为一组shell图像找到合适的base_points,然后你可以提供你想要的任何输入图像并覆盖它。

输出:

enter image description here