GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Jun-2012, 00:57
stbb24 stbb24 is offline
New Member
 
Join Date: May 2012
Posts: 14
stbb24 is on a distinguished road

Divide image into 8x8 blocks


Can anyone give tips on how to divide an image into 8x8 blocks using opencv and c++?
  #2  
Old 12-Jun-2012, 07:27
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,148
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Divide image into 8x8 blocks


Quote:
Originally Posted by stbb24
Can anyone give tips on how to divide an image into 8x8 blocks using opencv and c++?
I have a couple of questions:
  1. How are you going to store the image pixel values in memory?

  2. What are you going to do with 8x8 blocks of pixels values? (Operate on them in-place or create separate arrays or what?)


Regards,

Dave
__________________
Sometimes I just can't help myself...
  #3  
Old 13-Jun-2012, 23:48
stbb24 stbb24 is offline
New Member
 
Join Date: May 2012
Posts: 14
stbb24 is on a distinguished road

Re: Divide image into 8x8 blocks


I'm using opencv and c++. I need to divide the image into 8x8 blocks and then apply dct afterwards to the 8x8 blocks.
  #4  
Old 14-Jun-2012, 18:07
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,148
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Divide image into 8x8 blocks


Quote:
Originally Posted by stbb24
I'm using opencv and c++. I need to divide the image into 8x8 blocks and then apply dct afterwards to the 8x8 blocks.

Try something like
CPP / C++ / C Code:
#include <iostream>
#include <opencv2/highgui/highgui.hpp>

using namespace std;
using namespace cv;

int main(int argc, char ** argv)
{
    const char *fileName = "../baboon.jpg";

    if (argc > 1)
    {
        fileName = argv[1];
    }

    //
    // For your reference: Some image types of interest:
    //
    cout << "CV_8UC1  = " << CV_8UC1  << endl;
    cout << "CV_8UC3  = " << CV_8UC3  << endl;
    cout << "CV_32FC1 = " << CV_32FC1 << endl;
    cout << "CV_32FC3 = " << CV_32FC3 << endl;
    cout << "CV_64FC1 = " << CV_64FC1 << endl;
    cout << "CV_64FC3 = " << CV_64FC3 << endl;


    Mat originalImage = imread(fileName, 1); 
    // Check to make sure it's valid
    if (originalImage.empty() || (originalImage.data == NULL))
    {
        cout << "Can't load image from " << fileName << "!" << endl;
        exit(EXIT_FAILURE);
    }
    cout << "Working on image from " << fileName << endl;

    //
    // Show what we have so far
    //
    int x = 0;
    int y = 0;

    namedWindow("Original", CV_WINDOW_AUTOSIZE);
    moveWindow("Original", x, y);
    imshow("Original", originalImage);
    x += 100;
    y += 100;

    int width = originalImage.size().width;
    int height = originalImage.size().width;

    cout << "Original image Width x Height is " << width << "x" << height << endl;

    // Leave original alone, work on a copy
    Mat dctImage = originalImage.clone();

    // Step through the copied image with rectangles size 8x8
    // For each block, split into planes, do dct, and merge back
    // into the block.  (This will affect the image from
    // which the block is selected each time.)

    for (int i = 0; i < height; i += 8) {
        for (int j = 0; j < width; j+= 8) {
            Mat block = dctImage(Rect(i, j, 8, 8));
            vector<Mat> planes;
            split(block, planes);
            vector<Mat> outplanes(planes.size());
            for (size_t k = 0; k < planes.size(); k++)
            {
                planes[k].convertTo(planes[k], CV_32FC1);
                dct(planes[k], outplanes[k]);
                outplanes[k].convertTo(outplanes[k], CV_8UC1);
            }
            merge(outplanes, block);
        }
    }
    namedWindow("dctBlockImage");
    moveWindow("dctBlockImage", x, y);
    imshow("dctBlockImage", dctImage);
    x += 100;
    y += 100;
.
. // Whatever else you want to do
.
    
    waitKey(0); 

    destroyAllWindows();
}


Regards,

Dave
__________________
Sometimes I just can't help myself...
 
 

Recent GIDBlogConfiguring iptables for Webmin Servers Index Module by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with updating itk image in Qt user interface Angobar C++ Forum 0 12-Sep-2011 06:33
how to do basic image processing using MFC yuhui MS Visual C++ / MFC Forum 5 08-Aug-2006 05:43
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Writing image to folder misunderstood MySQL / PHP Forum 4 17-Jun-2004 07:18
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:08.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.