matlab - 如何将图片插入手机壳

标签 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

是否有任何图像处理算法可用于自动化此过程?

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

最佳答案

编辑:

这是使用 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

关于matlab - 如何将图片插入手机壳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31253186/

相关文章:

c - 升级到 macOS Mojave 后,MATLAB 不再卸载 MEX 文件

matlab - 在matlab中快速计算图像的梯度

c++ - Qt3DRender : How to render an isosurface from quadrilateral patches?

javascript - 使用 Three.js 从一侧看不到脸

c++ - 在 C++ 中将 2D 屏幕坐标转换为 3D 空间坐标?

algorithm - 我该如何优化这个索引算法

android - Simulink-Matlab:Android音频捕获

matlab - HSV 和灰度强度有什么区别?

通过在规则网格上采样的位移场进行图像变形

Android - 缩放设备屏幕捕获的图像