2

So I have a function that receives OpenCV image and turns it into gray-scale.

    void UseLSD(IplImage* destination)
    {   
    IplImage *destinationForGS = cvCreateImage(cvSize(destination->width, destination->height),IPL_DEPTH_8U,1);
    cvCvtColor(destination,destinationForGS,CV_RGB2GRAY); 
}

How now to cut that image into images of size 10x10 pixels and iterate true them? (width and height may not divide on 10 but if there would be some loss (like loss from 1*h to 9*h+9*h pixels per image) it would be OK for me. ) BTW can you output one of 10*10 images onto screen. please.

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
Rella
  • 65,003
  • 109
  • 363
  • 636

2 Answers2

4

You can crop your images into small pieces like this (iteration not tested):

// source image
IplImage *source = cvLoadImage("lena.jpg", 1);
int roiSize = 10;
for(int j = 0; j < source->width/roiSize; ++j) {
    for(int i = 0; i < source->height/roiSize; ++i) {    
        cvSetImageROI(source, cvRect(i*roiSize, j*roiSize, roiSize, roiSize));

        // cropped image
        IplImage *cropSource = cvCreateImage(cvGetSize(source), source->depth, source->nChannels);

        // copy
        cvCopy(source, cropSource, NULL);

        // ... do what you want with your cropped image ...

        // always reset the ROI
        cvResetImageROI(source);
    }
}
Stéphane Péchard
  • 2,013
  • 3
  • 22
  • 35
  • Can OpenCV die on big images? – Rella Feb 02 '11 at 14:44
  • OpenCV probably not, your computer maybe :-) What do you call big images? – Stéphane Péchard Feb 02 '11 at 14:45
  • And What can something like OpenCV Error: Assertion failed (rect.width >= 0 && rect.height >= 0 && rect.x < image->width && rect.y < image->height && rect.x + rect.width >= (int)(rect.widt h > 0) && rect.y + rect.height >= (int)(rect.height > 0)) in unknown function, f ile ..\..\..\..\ocv\opencv\src\cxcore\cxarray.cpp, line 3000 mean? – Rella Feb 02 '11 at 14:47
  • cold you add source for outputing one of 10*10 images onto screen. please. – Rella Feb 02 '11 at 14:58
  • @Kabumbus : it looks like you try to access the image out of its limits (<0 or >[width,height]) – Stéphane Péchard Feb 02 '11 at 15:02
  • @Kabumbus: First, you won't see a thing on a 10*10 image. Then, look at OpenCV documentation about highgui, you'll find everything you need to display an image on screen (cvNamedWindow() and cvShowImage()). – Stéphane Péchard Feb 02 '11 at 15:04
4

I think the simplest solution is to use Regions of Interest. Here is sample

    /* load image */
    IplImage *img1 = cvLoadImage("elvita.jpg", 1);

    /* sets the Region of Interest 
       Note that the rectangle area has to be __INSIDE__ the image 
       You just iterate througt x and y.
   */
    cvSetImageROI(img1, cvRect(x*10, y*10, x*10 + 10, y*10 + 10));

    /* create destination image 
       Note that cvGetSize will return the width and the height of ROI */
    IplImage *img2 = cvCreateImage(cvGetSize(img1), 
                                   img1->depth, 
                                   img1->nChannels);

    /* copy subimage */
    cvCopy(img1, img2, NULL);

    /* always reset the Region of Interest */
    cvResetImageROI(img1);
Andrey
  • 59,039
  • 12
  • 119
  • 163