本文用 Python 实现 PS 的一种滤镜效果,称为万花筒。也是对图像做各种扭曲变换,最后图像呈现的效果就像从万花筒中看到的一样:

图像的效果可以参考之前的博客:

http://blog.csdn.net/matrix_space/article/details/46789783

import matplotlib.pyplot as plt
from skimage import io
from skimage import img_as_float
import numpy as np
import numpy.matlib
import math file_name='D:/Visual Effects/PS Algorithm/4.jpg';
img=io.imread(file_name) img = img_as_float(img) row, col, channel = img.shape # set the parameters
radius = 100.0
angle = math.pi/3
angle2 = math.pi/4
sides = 10.0
# set the center of the circle, proportion of the image size
centerX = 0.5
centerY = 0.5 iWidth=col
iHeight=row center_x=iWidth*centerX
center_y=iHeight*centerY xx = np.arange (col)
yy = np.arange (row) x_mask = numpy.matlib.repmat (xx, row, 1)
y_mask = numpy.matlib.repmat (yy, col, 1)
y_mask = np.transpose(y_mask) xx_dif = x_mask - center_x
yy_dif = y_mask - center_y r = np.sqrt(xx_dif * xx_dif + yy_dif * yy_dif)
theta = np.arctan2(yy_dif, xx_dif+0.0001) - angle - angle2
temp_theta=theta/math.pi*sides*0.5
temp_r = np.mod(temp_theta, 1.0)
mask_1 = temp_r < 0.5
theta = temp_r * 2 * mask_1 + (1-temp_r) * 2 * (1 - mask_1) radius_c=radius/np.cos(theta) temp_r = np.mod (r/radius_c, 1.0)
mask_1 = temp_r < 0.5
r = radius_c * (temp_r * 2 * mask_1 + (1-temp_r) * 2 * (1 - mask_1)) theta = theta + angle x1_mask = r * np.cos(theta) + center_x
y1_mask = r * np.sin(theta) + center_y mask = x1_mask < 0
x1_mask = x1_mask * (1 - mask)
mask = x1_mask > (col - 1)
x1_mask = x1_mask * (1 - mask) + (x1_mask * 0 + col -2) * mask mask = y1_mask < 0
y1_mask = y1_mask * (1 - mask)
mask = y1_mask > (row -1)
y1_mask = y1_mask * (1 - mask) + (y1_mask * 0 + row -2) * mask img_out = img * 1.0 int_x = np.floor (x1_mask)
int_x = int_x.astype(int)
int_y = np.floor (y1_mask)
int_y = int_y.astype(int) p_mask = x1_mask - int_x
q_mask = y1_mask - int_y img_out = img * 1.0 for ii in range(row):
for jj in range (col):
new_xx = int_x [ii, jj]
new_yy = int_y [ii, jj]
# p = p_mask[ii, jj]
# q = q_mask[ii, jj] img_out[ii, jj, :] = img[new_yy, new_xx, :] plt.figure (1)
plt.imshow (img)
plt.axis('off') plt.figure (2)
plt.imshow (img_out)
plt.axis('off') plt.show()

Python: PS 滤镜--万花筒效果的更多相关文章

  1. PS 滤镜— — 万花筒效果

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...

  2. Python: PS 滤镜--旋涡特效

    本文用Python 实现 PS 滤镜的旋涡特效,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/42215 ...

  3. Python: PS 滤镜--USM 锐化

    本文用 Python 实现 PS 滤镜中的 USM 锐化效果,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/detail ...

  4. Python: PS 滤镜--素描

    本文用 Python 实现 PS 滤镜中的素描特效,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/386 ...

  5. Python: PS 滤镜--表面模糊

    本文用 Python 实现 PS 滤镜中的表面模糊,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/528 ...

  6. Python: PS 滤镜--旋转模糊

    本文用 Python 实现 PS 滤镜中的旋转模糊,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/392 ...

  7. Python: PS滤镜--径向模糊

    本文用 Python 实现 PS 滤镜中的径向模糊特效,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/3 ...

  8. Python: PS 滤镜--马赛克

    本文利用 Python 实现PS 滤镜中的马赛克效果,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/30 ...

  9. Python: PS 滤镜--波浪特效

    本文用 Python 实现 PS 滤镜的波浪特效,具体效果可以参考之前的博客 http://blog.csdn.net/matrix_space/article/details/42215221 im ...

随机推荐

  1. 合并多个MP4文件

    把多个MP4文件连接起来的方法与音频文件不太一样,比较有效的方法是: $ cat mylist.txt file '/path/to/file1' file '/path/to/file2' file ...

  2. Buffer.isBuffer()详解

    Buffer.isBuffer(obj) obj {Object} 返回:{Boolean} 如果 obj 是一个 Buffer 则返回 true.

  3. js 小练习

    js 学习之路代码记录 js 加载时间线 1.创建Document对象,开始解析web页面.解析HTML元素和他们的文本内容后添加Element对象和Text节点到文档中.这个阶段document.r ...

  4. 如何使用JDK1.6 API

    如何使用JDK1.6 API-------https://jingyan.baidu.com/article/54b6b9c0e39a102d583b47d5.html  

  5. linux 下CPU数量、核心数量、是否支持超线程的判断

    判断依据:1.具有相同core id的cpu是同一个core的超线程.2.具有相同physical id的cpu是同一颗cpu封装的线程或者cores. 英文版:1.Physical id and c ...

  6. bzoj4553 [Tjoi2016&Heoi2016]序列 树状数组(区间最大值)+cqd

    [Tjoi2016&Heoi2016]序列 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1006  Solved: 464[Submit][ ...

  7. Python模块:time、datetime、random、os、sys、optparse

    time模块的方法: 时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量. struct_time时间元组,共有九个元素组.如下图: time.localtime([secs]): ...

  8. 饭卡-HDU2546(01背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2546 饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory L ...

  9. easyui webuploader 文件上传演示

    webuploader 上传首页 webuploader 上传前页面 webuploader 上传中页面 图就不上传了,状态会编程上传中 webuploader 已上传页面

  10. apache.commons.lang.StringUtils 使用心得

    原文:http://blog.csdn.net/ye_sheng/article/details/48101901?ref=myread 在Java中我们用的最多的类应该就是String了.对于Str ...