#include <iostream>

#include <opencv2/core/core.hpp>

#include <opencv2/highgui/highgui.hpp>

// function that creates and returns an image

cv::Mat function() {

        // create image

        cv::Mat ima(240,320,CV_8U,cv::Scalar(100));

        // return it

        return ima;

}

int main() {

        // create image

        cv::Mat image;

        // print image size

        std::cout << "size: " << image.size().height << " , "

          << image.size().width << std::endl;

        // open image

        image=  cv::imread("img.jpg");

        // check if image has been successfully read

        if (!image.data) {

                // no image has been created^Å

                return 0;

        }

        // print image size

    std::cout << "size (after reading): " << image.size().height << " , "

          << image.size().width << std::endl;

        // display image

        cv::namedWindow("Original Image"); // define the window

        cv::imshow("Original Image", image); // show the image

        // create another image

        cv::Mat result;

        // flip the image

        cv::flip(image,result,1); // positive for horizontal

                              // 0 for vertical

                              // negative for both

        // display result

        cv::namedWindow("Output Image");

        cv::imshow("Output Image", result);

        // wait for key pressed

        cv::waitKey(0);

        // write image on file

        cv::imwrite("output.bmp", result);

        // create two new images

        cv::Mat image2, image3;

        image2= result; // the two images refer to the same data

        result.copyTo(image3); // a new copy is created

        // flip vertically this time

        cv::flip(result,result,0);

        // display result

        cv::namedWindow("image 2");

        cv::imshow("image 2", image2);

        cv::namedWindow("image 3");

        cv::imshow("image 3", image3);

        // get a gray-level image

        //cv::Mat gray= function();

        // display result

        //cv::namedWindow("Gray Image");

        //cv::imshow("Gray Image", gray);

        // wait for key pressed

        cv::waitKey(0);

        return 1;

}

#transpose.py

#!/usr/bin/python

# Flip an image left-right

import os

import sys

import argparse

# If math processing is going to be needed add

#import math

import Image as pil

parser= argparse.ArgumentParser(description = 'Flip a png image left-to-right')

if len(sys.argv) == 1:

  sys.exit("Usage: png_image_flip file.png ")

  exit()

elif len(sys.argv) == 2:

  infilename = sys.argv[1]

else:

  sys.exit("Usage: png_image_flip file.png ")

  exit()

myimage = pil.open(infilename)

mirror = myimage.transpose(pil.FLIP_LEFT_RIGHT)

outfilename = os.path.splitext(os.path.basename(infilename))[0]+'_flip.png'

mirror.save(outfilename)

exit()

#transpose_image3.py

import cv2

import numpy as np

def update():

    global ind

    ind = ind%4

    for j in xrange(rows):

        for i in xrange(cols):

            if ind == 0:   # Resize and center the image

                if 0.25*cols< i <0.75*cols and 0.25*rows< j <0.75*rows:

                    map_x.itemset((j,i),2*( i - cols*0.25 ) + 0.5)

                    map_y.itemset((j,i),2*( j - rows*0.25 ) + 0.5)

                else:     # Other pixel values set to zero

                    map_x.itemset((j,i),0)

                    map_y.itemset((j,i),0)

            elif ind == 1: # Flip image in vertical direction, alternatively you can use $

                map_x.itemset((j,i),i)

                map_y.itemset((j,i),rows-j)

            elif ind == 2: # Flip image in horizontal direction, you can use np.fliplr or$

                map_x.itemset((j,i),cols-i)

                map_y.itemset((j,i),j)

            elif ind == 3: # Flip image in both the directions, you can use cv2.flip(flag$

                map_x.itemset((j,i),cols-i)

                map_y.itemset((j,i),rows-j)

    ind = ind+1

img = cv2.imread('img.jpg')

ind = 0

map_x = np.zeros(img.shape[:2],np.float32)

map_y = np.zeros(img.shape[:2],np.float32)

rows,cols = img.shape[:2]

while(True):

    update()

    dst = cv2.remap(img,map_x,map_y,cv2.INTER_LINEAR)

    cv2.imshow('dst',dst)

    if cv2.waitKey(1000)==27:

        break

cv2.destroyAllWindows()