# -*- coding: utf-8 -*-
"""
Created on Wed Apr 12 23:53:35 2017
@author: test
"""
from skimage import io,data
import matplotlib.pyplot as plt
import numpy as np
img=io.imread('0413.jpg')
rows,cols,dims=img.shape
row1 = int(rows/2)
img1 = np.uint8(np.zeros((rows,cols,3)))
img2 = np.uint8(np.zeros((rows,cols,3)))
img3 = np.uint8(np.zeros((rows,cols,3)))
img4=img.copy()
col4 = int(cols/2)
img5=img.copy()
row6 = int(rows/3)
col6 = int(cols/3)
img6 = np.uint8(np.zeros((row6,col6,3)))
row7 = int(rows*2)
col7 = int(cols*2)
img7 = np.uint8(np.zeros((row7,col7,3)))
img8 = np.uint8(np.zeros((cols,rows,3)))
img9 = np.uint8(np.zeros((rows,cols,3)))
plt.figure(num='柯P',figsize=(12,12))#1 inch = 0.39cm
#origin
plt.subplot(3,3,5)
plt.title('origin image')
plt.imshow(img5)
#half down
for i in range(0,row1):
    for j in range(0,cols):
        for k in range(0,3):
            img1[i,j,k] = img[rows-row1+i,j,k]
for i in range(row1,rows):
    for j in range(0,cols):
        for k in range(0,3):
            img1[i,j,k] = img[i,j,k]
plt.subplot(3,3,1)
plt.title('half down')
plt.imshow(img1)
#mirror updown
for i in range(0,rows):
    for j in range(0,cols):
        for k in range(0,3):
            img2[i,j,k] = img[rows-1-i,j,k]
plt.subplot(3,3,2)
plt.title('mirror updown')
plt.imshow(img2)
#mirror leftright
for i in range(0,rows):
    for j in range(0,cols):
        for k in range(0,3):
            img3[i,j,k] = img[i,cols-1-j,k]
plt.subplot(3,3,3)
plt.title('mirror leftright')
plt.imshow(img3)
io.imsave('mirrorleftright.jpg',img3)
#half left
for i in range(0,rows):
    for j in range(0,col4):
        for k in range(0,3):
            img4[i,j,k] = img4[i,j,k]
for i in range(0,rows):
    for j in range(col4,cols):
        for k in range(0,3):
            img4[i,j,k] = img4[i,j-col4,k]
plt.subplot(3,3,4)
plt.title('half left')
plt.imshow(img4)
#decrease to 1/3
for i in range(0,row6):
    for j in range(0,col6):
        for k in range(0,3):
            sum = 0
            for l in range(0,3):
                for m in range(0,3):
                    sum = sum + img[3*i+l,3*j+m,k]
            img6[i,j,k] = np.uint8(sum/9)
plt.subplot(3,3,6)
plt.title('decrease 1/3')
plt.imshow(img6)
#magnify 4 times
for i in range(0,rows):
    for j in range(0,cols):
        for k in range(0,3):
            for l in range(2*i,2*(i+1)):
                for m in range(2*j,2*(j+1)):
                    img7[l,m,k] = img[i,j,k]
plt.subplot(3,3,7)
plt.title('magnify 2 times')
plt.imshow(img7)

#rotate right 90 degree
for i in range(0,rows):
    for j in range(0,cols):
        for k in range(0,3):
            img8[j,rows-1-i,k] = img[i,j,k]
plt.subplot(3,3,8)
plt.title('rotate right 90')
plt.imshow(img8)
#rotate 180 degree
for i in range(0,rows):
    for j in range(0,cols):
        for k in range(0,3):
            img9[rows-1-i,cols-1-j,k] = img[i,j,k]
plt.subplot(3,3,9)
plt.imshow(img9)
plt.show()