blImageShifting — Shift images by any desired amount in any direction for any purporse

This entry is part 12 of 17 in the series blImageAPI -- BarbatoLabs Image API

Introduction

In this very short article I will collect all the different functions I have and will develop to shift images by any number of pixels in any direction using the blImageAPI.

Shifting images can come up in many occasions, although in my case I use this function to calculate the Fast Fourier Transform of images, which I will show in a different article very soon.

List of functions

Here I list the current functions I have include so far. The list will grow, so make sure to come back for updates.

Note: The images can be of any size or any type

  1. ShiftImageByMRowsAndNCols

    1. Used to shift an image by M rows and N columns.
    2. The function takes a source image and a destination image.  (They can point to the same image if desired)

The code

I have put all the functions in a file called blImageShifting.hpp which follows:

blImageShifting.hpp (Click to see code…)

Usage

The following snippet grabs images from the webcam and shifts them using a sin function.

int main(int argc, char *argv[])
{
    // Connect to the webcam
    blCaptureDevice Webcam;
    Webcam.ConnectToWebcam(0);

    // The webcam frame (in grayscale)
    blImage< blColor3<float> > Frame;

    // The shifted image
    blImage< blColor3<float> > ShiftedFrame;

    // How many rows to shift by
    int M = 0;

    // How many columns to shift by
    int N = 0;

    // Create a key variable to
    // quit program when user
    // hits the 'q' key
    int key = 'a';

    // Loop through and keep querying
    // frames from webcam until user
    // hits the 'q' key
    while(key != 'q')
    {
        // Change how many rows
        // and cols to shift by
        ++M;
        N = 160*std::sin(0.1*double(M));

        // Query a frame from the webcam
        Webcam.QueryFrame(Frame);

        // Show the webcam frame
        cvShowImage("Webcam Frame",Frame);

        // Shift the frame and store
        // it into the ShiftedFrame
        ShiftImageByMRowsAndNCols(Frame,ShiftedFrame,M,N);

        // Show the shifted frame
        cvShowImage("Shifted Frame",ShiftedFrame);

        // Wait for a key
        key = cvWaitKey(1);
    }
}

The resulting output from the snippet follows:

Downloads

I have put all the files into a zip file which can be downloaded here. All you have to do is extract it somewhere, let’s say in a directory called blImageAPI, and then include the blImageAPI.hpp file as follows:

#include "blImageAPI/blImageAPI.hpp"
using namespace blImageAPI;

Note:  Everything is declared in a namespace blImageAPI, and such you would use it as: blImageAPI::blImage

blImageAPI.zip -- Ver Jun/06/2011 1:43pm (4992)

Updates

I will be adding more functions as I develop them, so check back soon for updates

About Vincenzo Barbato

Known to his friends as Enzo, he's an outside-the-box engineer/researcher whose interests and expertise span many fields, including controls systems, multi-physics simulations, mechatronics, oil technologies, data analysis and machine vision just to name a few.

Refusing to grow up, he's on a continuous journey to develop simple and creative solutions that have the power of disrupting industries by optimizing systems and processes.

Married to a beautiful wife, with two beautiful daughters and two identical twin boys, his home is a never ending chaotic fountain of inspiration.

His outlook on life:

"Never blindly accept what you're told, listen, but then question, with curiosity, creativity and collaboration we can change the world"

About Enzo

Known to his friends as Enzo, he's an outside-the-box engineer/researcher whose interests and expertise span many fields, including controls systems, multi-physics simulations, mechatronics, oil technologies, data analysis and machine vision just to name a few. Refusing to grow up, he's on a continuous journey to develop simple and creative solutions that have the power of disrupting industries by optimizing systems and processes. Married to a beautiful wife, with two beautiful daughters and two identical twin boys, his home is a never ending chaotic fountain of inspiration. His outlook on life: "Never blindly accept what you're told, listen, but then question, with curiosity, creativity and collaboration we can change the world"

Leave a Reply

Your email address will not be published. Required fields are marked *