Saving Multiple Blocks of an image

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Saving Multiple Blocks of an image

opencv-users mailing list
Dear Sir,
Please help in saving blocks of an image in this code after dividing the image in different folder.
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <fstream>

#include <conio.h>#include "opencv\cvaux.h"#include "opencv\highgui.h"

#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/core/core.hpp"
using namespace std;using namespace cv;
int main( int argc, char** argv ){Mat image;char file[256];sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");cvSaveImage(file,1); image = imread("secret_image.tiff",1);if(image.empty()){cout << "Could not open or find the image" << std::endl ;return -1;}

namedWindow("Image", CV_WINDOW_AUTOSIZE );imshow("Image", image);

   // get the image data int height = image.rows; int width = image.cols;
 printf("Processing a %dx%d image\n",height,width);
cv :: Size smallSize ( 64 , 64 );
std :: vector < Mat > smallImages ;namedWindow("smallImages", CV_WINDOW_AUTOSIZE );
for  ( int y =  0 ; y < image . rows ; y += smallSize . height ){    for  ( int x =  0 ; x < image . cols ; x += smallSize . width )    {        cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );        smallImages . push_back ( cv :: Mat ( image , rect )); sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages); imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );        imshow ( "smallImages",cv :: Mat ( image , rect ) ); waitKey(0); } }return 0; }

Thanks and regardsDeepak
Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list

/*

 This cuts a 64 x 64 block out of my "sample.tif" and is put into a smaller mat "rect" and is saved
to the hard dirve as "smallImage.tif".
tif file are uncompressed. jpg are so the take up less space.

 Compiled in the consule terminal with:

g++ pro.cpp -o pro `pkg-config --cflags --libs opencv`

 Run it in the consule:

./pro


*/

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>


#include <conio.h> //this does not work on my linux machine

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"


using namespace std;
using namespace cv;

  int main( int argc, char** argv )
    {
      Mat image;

//            char file[256];
            char file_Bytes[256];
      cout << "file is 256 bytes\n";
//      sprintf(file_Bytes,"%s","/DEEPAK/My Documents/opencvdatabase/result1");
//      cvSaveImage(file,1);
//      imagewire("file_Bytes", file_Bytes_handle)


      //image = imread("secret_image.tiff",1); // secret_image.tiff or secret_image.tif
      image = imread("sample.tif", 1 ); //must be bigher than 64 x 64
//      image = imread("red.jpg", 1 );


      if(! image.data )                             // Check for invalid input
                      {
                        cout << "Could not open or find the image" << std::endl ;
                        return -1;
                       }

//      get the image data
      int height = image.rows;
      int width = image.cols;

      printf("Processing a %dx%d image\n",height,width);

//      Size smallSize ( 64 , 64 );

//      std :: vector < Mat > smallImages ;
//       Rect rect =  Rect ( x , y , smallSize . width , smallSize.height );

//////This is where the magic happens////////////////////////////////////

      Mat rect(image, Rect(0, 0, 64, 64)); //smallImage is a 64 by 64 image cut out form a bigget image starting at y = 0, x = 0

////////////////////////////////////////////


//      imgSrc.copyTo(smallSize);



//      sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages);
      cout << "smallImage is a 64 by 64 image cut out form a bigget image starting at y = 0, x = 0\n";
      namedWindow("smallImages", CV_WINDOW_AUTOSIZE );
      imwrite ("smallImages.tif", rect);// jpg file take up less space.
      imshow ( "smallImages", rect);

      waitKey(0);
      return 0;
     }


Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list
In reply to this post by opencv-users mailing list
You can use this piece of code to divide an image into equal blocks.

int main()
{
Mat img = imread("1.jpg");
imshow("original", img);
waitKey(2000);

for(int i = 0; i <=img.rows - (img.rows/2); i = i + (img.rows/2))
{
for(int j = 0; j <=img.cols - (img.cols/2); j = j + (img.cols/2))
{
Mat sub(img, Rect(j, i, (img.rows/2), (img.rows/2) ));
imwrite("sub" + to_string(static_cast<long long>(i)) +
to_string(static_cast<long long>(j)) +".jpg",sub);
}
}

system("pause");
return 0;
}


On Fri, Mar 27, 2015 at 7:48 PM, Deepak Achar [hidden email]
[OpenCV] <[hidden email]> wrote:

>
>
> Dear Sir,
>
> Please help in saving blocks of an image in this code after dividing the
> image in different folder.
>
> #include <iostream>
> #include <stdio.h>
> #include <stdlib.h>
> #include <fstream>
>
>
> #include <conio.h>
> #include "opencv\cvaux.h"
> #include "opencv\highgui.h"
>
>
> #include "opencv2/highgui/highgui.hpp"
> #include "opencv2/imgproc/imgproc.hpp"
> #include "opencv2/core/core.hpp"
>
> using namespace std;
> using namespace cv;
>
> int main( int argc, char** argv )
> {
> Mat image;
> char file[256];
> sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");
> cvSaveImage(file,1);
>
> image = imread("secret_image.tiff",1);
> if(image.empty())
> {
> cout << "Could not open or find the image" << std::endl ;
> return -1;
> }
>
>
> namedWindow("Image", CV_WINDOW_AUTOSIZE );
> imshow("Image", image);
>
>
>    // get the image data
>  int height = image.rows;
>  int width = image.cols;
>
>  printf("Processing a %dx%d image\n",height,width);
>
> cv :: Size smallSize ( 64 , 64 );
>
> std :: vector < Mat > smallImages ;
> namedWindow("smallImages", CV_WINDOW_AUTOSIZE );
>
> for  ( int y =  0 ; y < image . rows ; y += smallSize . height )
> {
>     for  ( int x =  0 ; x < image . cols ; x += smallSize . width )
>     {
>         cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width ,
> smallSize . height );
>         smallImages . push_back ( cv :: Mat ( image , rect ));
> sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages);
> imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );
>         imshow ( "smallImages",cv :: Mat ( image , rect ) );
> waitKey(0);
> }
> }
> return 0;
> }
>
>
> Thanks and regards
> Deepak
>
>  
>
Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list
In reply to this post by opencv-users mailing list

/*

 This cuts a image into 16 x16 blocks, 256 total files and image, and shows them to the screen, got room?
 The 256  smaller files are made out of the mother file "sample.tif" , or something close to that name, and
the smaller files are imwriten to the hard drive directory that this file was executed in.

 Compiled in the console terminal with:

g++ pro1.cpp -o pro1 `pkg-config --cflags --libs opencv`

 Run it in the console:

./pro1

*/

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <math.h>
#include <string.h>
#include <errno.h>

#include <conio.h> //this does not work on my linux machine

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"

using namespace std;
using namespace cv;

  int main( int argc, char** argv )
    {
      Mat image;

//      image = imread("secret_image.tiff",1); // CCITT_4.TIF
//      image = imread("sample.tif", 1 );

      image = imread("CCITT_4.TIF", 1 );

//      image = imread("red.jpg", 1 );
//      if(image.data)

      if(! image.data )                             // Check for invalid input
                      {
                        cout << "Could not open or find the image" << std::endl ;
                        return -1;
                       }

      // get the image data of maximum row and cols length
      unsigned int heightMx = image.rows;
      unsigned int widthMx = image.cols;
      unsigned int heightOne16th = heightMx / 16;
      unsigned int widthOne16th = widthMx / 16;
      // cout << "" <<  << "";
      cout << " heightMx is " << heightMx << "\n";
      cout << "widthMx is " << widthMx <<"\n";
      cout << " block size " << heightOne16th << " by " << widthOne16th << "\n";
      char titlefilename [64] ;

      unsigned int widthCount;
      unsigned int heightCount;

      for (heightCount = 0;heightCount < 1; heightCount = heightCount + 1)// just one run
//      for (heightCount = 0;heightCount < 16; heightCount = heightCount + 1)// if you do 16 it will be 256 files!!!!!!!!!!!!!
            {
//              for (widthCount = 0;widthCount < 3; widthCount = widthCount + 1)
              for (widthCount = 0;widthCount < 16; widthCount = widthCount + 1)
                {
//                  Mat rect(image, Rect(7 * widthOne16th, 15 * heightOne16th, widthOne16th, heightOne16th));
                  Mat rect(image, Rect(widthCount * widthOne16th, heightCount * heightOne16th, widthOne16th, heightOne16th));



                  snprintf (titlefilename, sizeof (titlefilename), "0smallImages_%dw_%dh.tif\n", widthCount, heightCount);

                  cout <<"  " << titlefilename << "\n";
                  fflush (stdout);

//                  namedWindow("smallImages", CV_WINDOW_AUTOSIZE );
                  namedWindow(titlefilename, CV_WINDOW_AUTOSIZE );
//                  const char titlelll[] = "smallImages.tif";

//                  imwrite (titlelll, rect);// jpg file take up less space.
//                  imwrite (titlefilename, rect);
                  imwrite (titlefilename, rect);
//                  imwrite ("smallImages.tif", rect);



//                  imshow ( "smallImages", rect);
                  imshow ( titlefilename, rect);
                 }
             }

      waitKey(0);
      return 0;
     }


Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list
In reply to this post by opencv-users mailing list
Hi SirI saved the image blocks in the hard disk. Thank you very much Sir.
Thanks and regardsDeepak


     On Sunday, 29 March 2015 4:40 PM, "Alrabi opencv [hidden email] [OpenCV]" <[hidden email]> wrote:
   

     You can use this piece of code to divide an image into equal blocks. 
int main(){ Mat img = imread("1.jpg"); imshow("original", img); waitKey(2000);
 for(int i = 0; i <=img.rows - (img.rows/2); i = i + (img.rows/2)) { for(int j = 0; j <=img.cols - (img.cols/2); j = j + (img.cols/2)) { Mat sub(img, Rect(j, i, (img.rows/2), (img.rows/2) )); imwrite("sub" + to_string(static_cast<long long>(i)) + to_string(static_cast<long long>(j)) +".jpg",sub); } }
 system("pause"); return 0;}

On Fri, Mar 27, 2015 at 7:48 PM, Deepak Achar [hidden email] [OpenCV] <[hidden email]> wrote:

     Dear Sir,
Please help in saving blocks of an image in this code after dividing the image in different folder.
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <fstream>

#include <conio.h>#include "opencv\cvaux.h"#include "opencv\highgui.h"

#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/core/core.hpp"
using namespace std;using namespace cv;
int main( int argc, char** argv ){Mat image;char file[256];sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");cvSaveImage(file,1); image = imread("secret_image.tiff",1);if(image.empty()){cout << "Could not open or find the image" << std::endl ;return -1;}

namedWindow("Image", CV_WINDOW_AUTOSIZE );imshow("Image", image);

   // get the image data int height = image.rows; int width = image.cols;
 printf("Processing a %dx%d image\n",height,width);
cv :: Size smallSize ( 64 , 64 );
std :: vector < Mat > smallImages ;namedWindow("smallImages", CV_WINDOW_AUTOSIZE );
for  ( int y =  0 ; y < image . rows ; y += smallSize . height ){    for  ( int x =  0 ; x < image . cols ; x += smallSize . width )    {        cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );        smallImages . push_back ( cv :: Mat ( image , rect )); sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages); imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );        imshow ( "smallImages",cv :: Mat ( image , rect ) ); waitKey(0); } }return 0; }

Thanks and regardsDeepak
   

  #yiv7296396201 #yiv7296396201 -- #yiv7296396201ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv7296396201 #yiv7296396201ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv7296396201 #yiv7296396201ygrp-mkp #yiv7296396201hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv7296396201 #yiv7296396201ygrp-mkp #yiv7296396201ads {margin-bottom:10px;}#yiv7296396201 #yiv7296396201ygrp-mkp .yiv7296396201ad {padding:0 0;}#yiv7296396201 #yiv7296396201ygrp-mkp .yiv7296396201ad p {margin:0;}#yiv7296396201 #yiv7296396201ygrp-mkp .yiv7296396201ad a {color:#0000ff;text-decoration:none;}#yiv7296396201 #yiv7296396201ygrp-sponsor #yiv7296396201ygrp-lc {font-family:Arial;}#yiv7296396201 #yiv7296396201ygrp-sponsor #yiv7296396201ygrp-lc #yiv7296396201hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv7296396201 #yiv7296396201ygrp-sponsor #yiv7296396201ygrp-lc .yiv7296396201ad {margin-bottom:10px;padding:0 0;}#yiv7296396201 #yiv7296396201actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv7296396201 #yiv7296396201activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv7296396201 #yiv7296396201activity span {font-weight:700;}#yiv7296396201 #yiv7296396201activity span:first-child {text-transform:uppercase;}#yiv7296396201 #yiv7296396201activity span a {color:#5085b6;text-decoration:none;}#yiv7296396201 #yiv7296396201activity span span {color:#ff7900;}#yiv7296396201 #yiv7296396201activity span .yiv7296396201underline {text-decoration:underline;}#yiv7296396201 .yiv7296396201attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv7296396201 .yiv7296396201attach div a {text-decoration:none;}#yiv7296396201 .yiv7296396201attach img {border:none;padding-right:5px;}#yiv7296396201 .yiv7296396201attach label {display:block;margin-bottom:5px;}#yiv7296396201 .yiv7296396201attach label a {text-decoration:none;}#yiv7296396201 blockquote {margin:0 0 0 4px;}#yiv7296396201 .yiv7296396201bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv7296396201 .yiv7296396201bold a {text-decoration:none;}#yiv7296396201 dd.yiv7296396201last p a {font-family:Verdana;font-weight:700;}#yiv7296396201 dd.yiv7296396201last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv7296396201 dd.yiv7296396201last p span.yiv7296396201yshortcuts {margin-right:0;}#yiv7296396201 div.yiv7296396201attach-table div div a {text-decoration:none;}#yiv7296396201 div.yiv7296396201attach-table {width:400px;}#yiv7296396201 div.yiv7296396201file-title a, #yiv7296396201 div.yiv7296396201file-title a:active, #yiv7296396201 div.yiv7296396201file-title a:hover, #yiv7296396201 div.yiv7296396201file-title a:visited {text-decoration:none;}#yiv7296396201 div.yiv7296396201photo-title a, #yiv7296396201 div.yiv7296396201photo-title a:active, #yiv7296396201 div.yiv7296396201photo-title a:hover, #yiv7296396201 div.yiv7296396201photo-title a:visited {text-decoration:none;}#yiv7296396201 div#yiv7296396201ygrp-mlmsg #yiv7296396201ygrp-msg p a span.yiv7296396201yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv7296396201 .yiv7296396201green {color:#628c2a;}#yiv7296396201 .yiv7296396201MsoNormal {margin:0 0 0 0;}#yiv7296396201 o {font-size:0;}#yiv7296396201 #yiv7296396201photos div {float:left;width:72px;}#yiv7296396201 #yiv7296396201photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv7296396201 #yiv7296396201photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv7296396201 #yiv7296396201reco-category {font-size:77%;}#yiv7296396201 #yiv7296396201reco-desc {font-size:77%;}#yiv7296396201 .yiv7296396201replbq {margin:4px;}#yiv7296396201 #yiv7296396201ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv7296396201 #yiv7296396201ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv7296396201 #yiv7296396201ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv7296396201 #yiv7296396201ygrp-mlmsg select, #yiv7296396201 input, #yiv7296396201 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv7296396201 #yiv7296396201ygrp-mlmsg pre, #yiv7296396201 code {font:115% monospace;}#yiv7296396201 #yiv7296396201ygrp-mlmsg * {line-height:1.22em;}#yiv7296396201 #yiv7296396201ygrp-mlmsg #yiv7296396201logo {padding-bottom:10px;}#yiv7296396201 #yiv7296396201ygrp-msg p a {font-family:Verdana;}#yiv7296396201 #yiv7296396201ygrp-msg p#yiv7296396201attach-count span {color:#1E66AE;font-weight:700;}#yiv7296396201 #yiv7296396201ygrp-reco #yiv7296396201reco-head {color:#ff7900;font-weight:700;}#yiv7296396201 #yiv7296396201ygrp-reco {margin-bottom:20px;padding:0px;}#yiv7296396201 #yiv7296396201ygrp-sponsor #yiv7296396201ov li a {font-size:130%;text-decoration:none;}#yiv7296396201 #yiv7296396201ygrp-sponsor #yiv7296396201ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv7296396201 #yiv7296396201ygrp-sponsor #yiv7296396201ov ul {margin:0;padding:0 0 0 8px;}#yiv7296396201 #yiv7296396201ygrp-text {font-family:Georgia;}#yiv7296396201 #yiv7296396201ygrp-text p {margin:0 0 1em 0;}#yiv7296396201 #yiv7296396201ygrp-text tt {font-size:120%;}#yiv7296396201 #yiv7296396201ygrp-vital ul li:last-child {border-right:none !important;}#yiv7296396201

 
Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list
Hi Sir
I am saving all the blocks and of the image. But I need continuity in saving the blocks like first it has to save blocks from pixel 1 to 512 and 64 to 512 etc. It is saving in different order. Please help regarding this. I have put the code for dividing blocks in continuity order.
Thanks and regards


     On Monday, 30 March 2015 9:58 AM, "Deepak Achar [hidden email] [OpenCV]" <[hidden email]> wrote:
   

     Hi SirI saved the image blocks in the hard disk. Thank you very much Sir.
Thanks and regardsDeepak


     On Sunday, 29 March 2015 4:40 PM, "Alrabi opencv [hidden email] [OpenCV]" <[hidden email]> wrote:
   

     You can use this piece of code to divide an image into equal blocks. 
int main(){ Mat img = imread("1.jpg"); imshow("original", img); waitKey(2000);
 for(int i = 0; i <=img.rows - (img.rows/2); i = i + (img.rows/2)) { for(int j = 0; j <=img.cols - (img.cols/2); j = j + (img.cols/2)) { Mat sub(img, Rect(j, i, (img.rows/2), (img.rows/2) )); imwrite("sub" + to_string(static_cast<long long>(i)) + to_string(static_cast<long long>(j)) +".jpg",sub); } }
 system("pause"); return 0;}

On Fri, Mar 27, 2015 at 7:48 PM, Deepak Achar [hidden email] [OpenCV] <[hidden email]> wrote:

     Dear Sir,
Please help in saving blocks of an image in this code after dividing the image in different folder.
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <fstream>

#include <conio.h>#include "opencv\cvaux.h"#include "opencv\highgui.h"

#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/core/core.hpp"
using namespace std;using namespace cv;
int main( int argc, char** argv ){Mat image;char file[256];sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");cvSaveImage(file,1); image = imread("secret_image.tiff",1);if(image.empty()){cout << "Could not open or find the image" << std::endl ;return -1;}

namedWindow("Image", CV_WINDOW_AUTOSIZE );imshow("Image", image);

   // get the image data int height = image.rows; int width = image.cols;
 printf("Processing a %dx%d image\n",height,width);
cv :: Size smallSize ( 64 , 64 );
std :: vector < Mat > smallImages ;namedWindow("smallImages", CV_WINDOW_AUTOSIZE );
for  ( int y =  0 ; y < image . rows ; y += smallSize . height ){    for  ( int x =  0 ; x < image . cols ; x += smallSize . width )    {        cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );        smallImages . push_back ( cv :: Mat ( image , rect )); sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages); imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );        imshow ( "smallImages",cv :: Mat ( image , rect ) ); waitKey(0); } }return 0; }

Thanks and regardsDeepak
   

 

     #yiv8703057441 #yiv8703057441 -- #yiv8703057441ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv8703057441 #yiv8703057441ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv8703057441 #yiv8703057441ygrp-mkp #yiv8703057441hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv8703057441 #yiv8703057441ygrp-mkp #yiv8703057441ads {margin-bottom:10px;}#yiv8703057441 #yiv8703057441ygrp-mkp .yiv8703057441ad {padding:0 0;}#yiv8703057441 #yiv8703057441ygrp-mkp .yiv8703057441ad p {margin:0;}#yiv8703057441 #yiv8703057441ygrp-mkp .yiv8703057441ad a {color:#0000ff;text-decoration:none;}#yiv8703057441 #yiv8703057441ygrp-sponsor #yiv8703057441ygrp-lc {font-family:Arial;}#yiv8703057441 #yiv8703057441ygrp-sponsor #yiv8703057441ygrp-lc #yiv8703057441hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv8703057441 #yiv8703057441ygrp-sponsor #yiv8703057441ygrp-lc .yiv8703057441ad {margin-bottom:10px;padding:0 0;}#yiv8703057441 #yiv8703057441actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv8703057441 #yiv8703057441activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv8703057441 #yiv8703057441activity span {font-weight:700;}#yiv8703057441 #yiv8703057441activity span:first-child {text-transform:uppercase;}#yiv8703057441 #yiv8703057441activity span a {color:#5085b6;text-decoration:none;}#yiv8703057441 #yiv8703057441activity span span {color:#ff7900;}#yiv8703057441 #yiv8703057441activity span .yiv8703057441underline {text-decoration:underline;}#yiv8703057441 .yiv8703057441attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv8703057441 .yiv8703057441attach div a {text-decoration:none;}#yiv8703057441 .yiv8703057441attach img {border:none;padding-right:5px;}#yiv8703057441 .yiv8703057441attach label {display:block;margin-bottom:5px;}#yiv8703057441 .yiv8703057441attach label a {text-decoration:none;}#yiv8703057441 blockquote {margin:0 0 0 4px;}#yiv8703057441 .yiv8703057441bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv8703057441 .yiv8703057441bold a {text-decoration:none;}#yiv8703057441 dd.yiv8703057441last p a {font-family:Verdana;font-weight:700;}#yiv8703057441 dd.yiv8703057441last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv8703057441 dd.yiv8703057441last p span.yiv8703057441yshortcuts {margin-right:0;}#yiv8703057441 div.yiv8703057441attach-table div div a {text-decoration:none;}#yiv8703057441 div.yiv8703057441attach-table {width:400px;}#yiv8703057441 div.yiv8703057441file-title a, #yiv8703057441 div.yiv8703057441file-title a:active, #yiv8703057441 div.yiv8703057441file-title a:hover, #yiv8703057441 div.yiv8703057441file-title a:visited {text-decoration:none;}#yiv8703057441 div.yiv8703057441photo-title a, #yiv8703057441 div.yiv8703057441photo-title a:active, #yiv8703057441 div.yiv8703057441photo-title a:hover, #yiv8703057441 div.yiv8703057441photo-title a:visited {text-decoration:none;}#yiv8703057441 div#yiv8703057441ygrp-mlmsg #yiv8703057441ygrp-msg p a span.yiv8703057441yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv8703057441 .yiv8703057441green {color:#628c2a;}#yiv8703057441 .yiv8703057441MsoNormal {margin:0 0 0 0;}#yiv8703057441 o {font-size:0;}#yiv8703057441 #yiv8703057441photos div {float:left;width:72px;}#yiv8703057441 #yiv8703057441photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv8703057441 #yiv8703057441photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv8703057441 #yiv8703057441reco-category {font-size:77%;}#yiv8703057441 #yiv8703057441reco-desc {font-size:77%;}#yiv8703057441 .yiv8703057441replbq {margin:4px;}#yiv8703057441 #yiv8703057441ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv8703057441 #yiv8703057441ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv8703057441 #yiv8703057441ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv8703057441 #yiv8703057441ygrp-mlmsg select, #yiv8703057441 input, #yiv8703057441 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv8703057441 #yiv8703057441ygrp-mlmsg pre, #yiv8703057441 code {font:115% monospace;}#yiv8703057441 #yiv8703057441ygrp-mlmsg * {line-height:1.22em;}#yiv8703057441 #yiv8703057441ygrp-mlmsg #yiv8703057441logo {padding-bottom:10px;}#yiv8703057441 #yiv8703057441ygrp-msg p a {font-family:Verdana;}#yiv8703057441 #yiv8703057441ygrp-msg p#yiv8703057441attach-count span {color:#1E66AE;font-weight:700;}#yiv8703057441 #yiv8703057441ygrp-reco #yiv8703057441reco-head {color:#ff7900;font-weight:700;}#yiv8703057441 #yiv8703057441ygrp-reco {margin-bottom:20px;padding:0px;}#yiv8703057441 #yiv8703057441ygrp-sponsor #yiv8703057441ov li a {font-size:130%;text-decoration:none;}#yiv8703057441 #yiv8703057441ygrp-sponsor #yiv8703057441ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv8703057441 #yiv8703057441ygrp-sponsor #yiv8703057441ov ul {margin:0;padding:0 0 0 8px;}#yiv8703057441 #yiv8703057441ygrp-text {font-family:Georgia;}#yiv8703057441 #yiv8703057441ygrp-text p {margin:0 0 1em 0;}#yiv8703057441 #yiv8703057441ygrp-text tt {font-size:120%;}#yiv8703057441 #yiv8703057441ygrp-vital ul li:last-child {border-right:none !important;}#yiv8703057441

 
Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list
where is your code that is working for you?
Kindly attach your code again


On Mon, Mar 30, 2015 at 8:31 PM, Deepak Achar [hidden email]
[OpenCV] <[hidden email]> wrote:

>
>
> Hi Sir
>
> I am saving all the blocks and of the image. But I need continuity in
> saving the blocks like first it has to save blocks from pixel 1 to 512 and
> 64 to 512 etc. It is saving in different order. Please help regarding
> this. I have put the code for dividing blocks in continuity order.
>
> Thanks and regards
>
>
>
>   On Monday, 30 March 2015 9:58 AM, "Deepak Achar
> [hidden email] [OpenCV]" <[hidden email]> wrote:
>
>
>
>  Hi Sir
> I saved the image blocks in the hard disk. Thank you very much Sir.
>
> Thanks and regards
> Deepak
>
>
>
>   On Sunday, 29 March 2015 4:40 PM, "Alrabi opencv [hidden email]
> [OpenCV]" <[hidden email]> wrote:
>
>
>
>  You can use this piece of code to divide an image into equal blocks.
>
> int main()
> {
> Mat img = imread("1.jpg");
> imshow("original", img);
> waitKey(2000);
>
> for(int i = 0; i <=img.rows - (img.rows/2); i = i + (img.rows/2))
> {
> for(int j = 0; j <=img.cols - (img.cols/2); j = j + (img.cols/2))
> {
> Mat sub(img, Rect(j, i, (img.rows/2), (img.rows/2) ));
> imwrite("sub" + to_string(static_cast<long long>(i)) +
> to_string(static_cast<long long>(j)) +".jpg",sub);
> }
> }
>
> system("pause");
> return 0;
> }
>
>
> On Fri, Mar 27, 2015 at 7:48 PM, Deepak Achar [hidden email]
> [OpenCV] <[hidden email]> wrote:
>
>
>  Dear Sir,
>
> Please help in saving blocks of an image in this code after dividing the
> image in different folder.
>
> #include <iostream>
> #include <stdio.h>
> #include <stdlib.h>
> #include <fstream>
>
>
> #include <conio.h>
> #include "opencv\cvaux.h"
> #include "opencv\highgui.h"
>
>
> #include "opencv2/highgui/highgui.hpp"
> #include "opencv2/imgproc/imgproc.hpp"
> #include "opencv2/core/core.hpp"
>
> using namespace std;
> using namespace cv;
>
> int main( int argc, char** argv )
> {
> Mat image;
> char file[256];
> sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");
> cvSaveImage(file,1);
>
> image = imread("secret_image.tiff",1);
> if(image.empty())
> {
> cout << "Could not open or find the image" << std::endl ;
> return -1;
> }
>
>
> namedWindow("Image", CV_WINDOW_AUTOSIZE );
> imshow("Image", image);
>
>
>    // get the image data
>  int height = image.rows;
>  int width = image.cols;
>
>  printf("Processing a %dx%d image\n",height,width);
>
> cv :: Size smallSize ( 64 , 64 );
>
> std :: vector < Mat > smallImages ;
> namedWindow("smallImages", CV_WINDOW_AUTOSIZE );
>
> for  ( int y =  0 ; y < image . rows ; y += smallSize . height )
> {
>     for  ( int x =  0 ; x < image . cols ; x += smallSize . width )
>     {
>         cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width ,
> smallSize . height );
>         smallImages . push_back ( cv :: Mat ( image , rect ));
> sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages);
> imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );
>         imshow ( "smallImages",cv :: Mat ( image , rect ) );
> waitKey(0);
> }
> }
> return 0;
> }
>
>
> Thanks and regards
> Deepak
>
>
>
>
>
>
>  
>
Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list

I mailed it previoulsy

Sent from Yahoo Mail on Android

From:"Alrabi opencv [hidden email] [OpenCV]" <[hidden email]>
Date:Mon, Mar 30, 2015 at 8:51 PM
Subject:Re: [OpenCV] Saving Multiple Blocks of an image

 

where is your code that is working for you?

Kindly attach your code again 



On Mon, Mar 30, 2015 at 8:31 PM, Deepak Achar [hidden email] [OpenCV] <[hidden email]> wrote:

 

Hi Sir


I am saving all the blocks and of the image. But I need continuity in saving the blocks like first it has to save blocks from pixel 1 to 512 and 64 to 512 etc. It is saving in different order. Please help regarding this. I have put the code for dividing blocks in continuity order.


Thanks and regards




On Monday, 30 March 2015 9:58 AM, "Deepak Achar [hidden email] [OpenCV]" <[hidden email]> wrote:



 

Hi Sir

I saved the image blocks in the hard disk. Thank you very much Sir.


Thanks and regards

Deepak




On Sunday, 29 March 2015 4:40 PM, "Alrabi opencv [hidden email] [OpenCV]" <[hidden email]> wrote:



 

You can use this piece of code to divide an image into equal blocks. 


int main()

{

        Mat img = imread("1.jpg");

        imshow("original", img);

        waitKey(2000);


        for(int i = 0; i <=img.rows - (img.rows/2); i = i + (img.rows/2))

        {

                for(int j = 0; j <=img.cols - (img.cols/2); j = j + (img.cols/2))

                {

                        Mat sub(img, Rect(j, i, (img.rows/2), (img.rows/2) ));

                        imwrite("sub" + to_string(static_cast<long long>(i)) + to_string(static_cast<long long>(j)) +".jpg",sub);

                }

        }


        system("pause");

        return 0;

}



On Fri, Mar 27, 2015 at 7:48 PM, Deepak Achar [hidden email] [OpenCV] <[hidden email]> wrote:

 

Dear Sir,


Please help in saving blocks of an image in this code after dividing the image in different folder.


#include <iostream>

#include <stdio.h>

#include <stdlib.h>

#include <fstream>



#include <conio.h>

#include "opencv\cvaux.h"

#include "opencv\highgui.h"



#include "opencv2/highgui/highgui.hpp"

#include "opencv2/imgproc/imgproc.hpp"

#include "opencv2/core/core.hpp"


using namespace std;

using namespace cv;


int main( int argc, char** argv )

{

Mat image;

char file[256];

sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");

cvSaveImage(file,1);

 

image = imread("secret_image.tiff",1);

if(image.empty())

{

cout << "Could not open or find the image" << std::endl ;

return -1;

}



namedWindow("Image", CV_WINDOW_AUTOSIZE );

imshow("Image", image);



   // get the image data

 int height = image.rows;

 int width = image.cols;


 printf("Processing a %dx%d image\n",height,width);


cv :: Size smallSize ( 64 , 64 );


std :: vector < Mat > smallImages ;

namedWindow("smallImages", CV_WINDOW_AUTOSIZE );


for  ( int y =  0 ; y < image . rows ; y += smallSize . height )

{

    for  ( int x =  0 ; x < image . cols ; x += smallSize . width )

    {

        cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );

        smallImages . push_back ( cv :: Mat ( image , rect ));

                sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages);

                imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );

        imshow ( "smallImages",cv :: Mat ( image , rect ) );

                waitKey(0);

        }

}

return 0;

                }



Thanks and regards

Deepak










Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list
In reply to this post by opencv-users mailing list
OK I will

Sent from Yahoo Mail on Android

From:"Alrabi opencv [hidden email] [OpenCV]" <[hidden email]>
Date:Mon, Mar 30, 2015 at 8:51 PM
Subject:Re: [OpenCV] Saving Multiple Blocks of an image

 

where is your code that is working for you?

Kindly attach your code again 



On Mon, Mar 30, 2015 at 8:31 PM, Deepak Achar [hidden email] [OpenCV] <[hidden email]> wrote:

 

Hi Sir


I am saving all the blocks and of the image. But I need continuity in saving the blocks like first it has to save blocks from pixel 1 to 512 and 64 to 512 etc. It is saving in different order. Please help regarding this. I have put the code for dividing blocks in continuity order.


Thanks and regards




On Monday, 30 March 2015 9:58 AM, "Deepak Achar [hidden email] [OpenCV]" <[hidden email]> wrote:



 

Hi Sir

I saved the image blocks in the hard disk. Thank you very much Sir.


Thanks and regards

Deepak




On Sunday, 29 March 2015 4:40 PM, "Alrabi opencv [hidden email] [OpenCV]" <[hidden email]> wrote:



 

You can use this piece of code to divide an image into equal blocks. 


int main()

{

        Mat img = imread("1.jpg");

        imshow("original", img);

        waitKey(2000);


        for(int i = 0; i <=img.rows - (img.rows/2); i = i + (img.rows/2))

        {

                for(int j = 0; j <=img.cols - (img.cols/2); j = j + (img.cols/2))

                {

                        Mat sub(img, Rect(j, i, (img.rows/2), (img.rows/2) ));

                        imwrite("sub" + to_string(static_cast<long long>(i)) + to_string(static_cast<long long>(j)) +".jpg",sub);

                }

        }


        system("pause");

        return 0;

}



On Fri, Mar 27, 2015 at 7:48 PM, Deepak Achar [hidden email] [OpenCV] <[hidden email]> wrote:

 

Dear Sir,


Please help in saving blocks of an image in this code after dividing the image in different folder.


#include <iostream>

#include <stdio.h>

#include <stdlib.h>

#include <fstream>



#include <conio.h>

#include "opencv\cvaux.h"

#include "opencv\highgui.h"



#include "opencv2/highgui/highgui.hpp"

#include "opencv2/imgproc/imgproc.hpp"

#include "opencv2/core/core.hpp"


using namespace std;

using namespace cv;


int main( int argc, char** argv )

{

Mat image;

char file[256];

sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");

cvSaveImage(file,1);

 

image = imread("secret_image.tiff",1);

if(image.empty())

{

cout << "Could not open or find the image" << std::endl ;

return -1;

}



namedWindow("Image", CV_WINDOW_AUTOSIZE );

imshow("Image", image);



   // get the image data

 int height = image.rows;

 int width = image.cols;


 printf("Processing a %dx%d image\n",height,width);


cv :: Size smallSize ( 64 , 64 );


std :: vector < Mat > smallImages ;

namedWindow("smallImages", CV_WINDOW_AUTOSIZE );


for  ( int y =  0 ; y < image . rows ; y += smallSize . height )

{

    for  ( int x =  0 ; x < image . cols ; x += smallSize . width )

    {

        cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );

        smallImages . push_back ( cv :: Mat ( image , rect ));

                sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages);

                imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );

        imshow ( "smallImages",cv :: Mat ( image , rect ) );

                waitKey(0);

        }

}

return 0;

                }



Thanks and regards

Deepak










Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list
In reply to this post by opencv-users mailing list
here is a code Sir
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <fstream>

#include <conio.h>#include "opencv\cvaux.h"#include "opencv\highgui.h"

#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/core/core.hpp"
using namespace std;using namespace cv;
int main( int argc, char** argv ){Mat image;char file[256];sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");cvSaveImage(file,1); image = imread("secret_image.tiff",1);if(image.empty()){cout << "Could not open or find the image" << std::endl ;return -1;}

namedWindow("Image", CV_WINDOW_AUTOSIZE );imshow("Image", image);

   // get the image data int height = image.rows; int width = image.cols;
 printf("Processing a %dx%d image\n",height,width);
cv :: Size smallSize ( 64 , 64 );
std :: vector < Mat > smallImages ;namedWindow("smallImages", CV_WINDOW_AUTOSIZE );
for  ( int y =  0 ; y < image . rows ; y += smallSize . height ){    for  ( int x =  0 ; x < image . cols ; x += smallSize . width )    {        cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );        smallImages . push_back ( cv :: Mat ( image , rect )); sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages); imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );        imshow ( "smallImages",cv :: Mat ( image , rect ) ); waitKey(0); } }return 0; }


     On Sunday, 29 March 2015 4:40 PM, "Alrabi opencv [hidden email] [OpenCV]" <[hidden email]> wrote:
   

     You can use this piece of code to divide an image into equal blocks. 
int main(){ Mat img = imread("1.jpg"); imshow("original", img); waitKey(2000);
 for(int i = 0; i <=img.rows - (img.rows/2); i = i + (img.rows/2)) { for(int j = 0; j <=img.cols - (img.cols/2); j = j + (img.cols/2)) { Mat sub(img, Rect(j, i, (img.rows/2), (img.rows/2) )); imwrite("sub" + to_string(static_cast<long long>(i)) + to_string(static_cast<long long>(j)) +".jpg",sub); } }
 system("pause"); return 0;}

On Fri, Mar 27, 2015 at 7:48 PM, Deepak Achar [hidden email] [OpenCV] <[hidden email]> wrote:

     Dear Sir,
Please help in saving blocks of an image in this code after dividing the image in different folder.
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <fstream>

#include <conio.h>#include "opencv\cvaux.h"#include "opencv\highgui.h"

#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/core/core.hpp"
using namespace std;using namespace cv;
int main( int argc, char** argv ){Mat image;char file[256];sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");cvSaveImage(file,1); image = imread("secret_image.tiff",1);if(image.empty()){cout << "Could not open or find the image" << std::endl ;return -1;}

namedWindow("Image", CV_WINDOW_AUTOSIZE );imshow("Image", image);

   // get the image data int height = image.rows; int width = image.cols;
 printf("Processing a %dx%d image\n",height,width);
cv :: Size smallSize ( 64 , 64 );
std :: vector < Mat > smallImages ;namedWindow("smallImages", CV_WINDOW_AUTOSIZE );
for  ( int y =  0 ; y < image . rows ; y += smallSize . height ){    for  ( int x =  0 ; x < image . cols ; x += smallSize . width )    {        cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );        smallImages . push_back ( cv :: Mat ( image , rect )); sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages); imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );        imshow ( "smallImages",cv :: Mat ( image , rect ) ); waitKey(0); } }return 0; }

Thanks and regardsDeepak
   

  #yiv1510208651 #yiv1510208651 -- #yiv1510208651ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv1510208651 #yiv1510208651ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv1510208651 #yiv1510208651ygrp-mkp #yiv1510208651hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv1510208651 #yiv1510208651ygrp-mkp #yiv1510208651ads {margin-bottom:10px;}#yiv1510208651 #yiv1510208651ygrp-mkp .yiv1510208651ad {padding:0 0;}#yiv1510208651 #yiv1510208651ygrp-mkp .yiv1510208651ad p {margin:0;}#yiv1510208651 #yiv1510208651ygrp-mkp .yiv1510208651ad a {color:#0000ff;text-decoration:none;}#yiv1510208651 #yiv1510208651ygrp-sponsor #yiv1510208651ygrp-lc {font-family:Arial;}#yiv1510208651 #yiv1510208651ygrp-sponsor #yiv1510208651ygrp-lc #yiv1510208651hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv1510208651 #yiv1510208651ygrp-sponsor #yiv1510208651ygrp-lc .yiv1510208651ad {margin-bottom:10px;padding:0 0;}#yiv1510208651 #yiv1510208651actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv1510208651 #yiv1510208651activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv1510208651 #yiv1510208651activity span {font-weight:700;}#yiv1510208651 #yiv1510208651activity span:first-child {text-transform:uppercase;}#yiv1510208651 #yiv1510208651activity span a {color:#5085b6;text-decoration:none;}#yiv1510208651 #yiv1510208651activity span span {color:#ff7900;}#yiv1510208651 #yiv1510208651activity span .yiv1510208651underline {text-decoration:underline;}#yiv1510208651 .yiv1510208651attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv1510208651 .yiv1510208651attach div a {text-decoration:none;}#yiv1510208651 .yiv1510208651attach img {border:none;padding-right:5px;}#yiv1510208651 .yiv1510208651attach label {display:block;margin-bottom:5px;}#yiv1510208651 .yiv1510208651attach label a {text-decoration:none;}#yiv1510208651 blockquote {margin:0 0 0 4px;}#yiv1510208651 .yiv1510208651bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv1510208651 .yiv1510208651bold a {text-decoration:none;}#yiv1510208651 dd.yiv1510208651last p a {font-family:Verdana;font-weight:700;}#yiv1510208651 dd.yiv1510208651last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv1510208651 dd.yiv1510208651last p span.yiv1510208651yshortcuts {margin-right:0;}#yiv1510208651 div.yiv1510208651attach-table div div a {text-decoration:none;}#yiv1510208651 div.yiv1510208651attach-table {width:400px;}#yiv1510208651 div.yiv1510208651file-title a, #yiv1510208651 div.yiv1510208651file-title a:active, #yiv1510208651 div.yiv1510208651file-title a:hover, #yiv1510208651 div.yiv1510208651file-title a:visited {text-decoration:none;}#yiv1510208651 div.yiv1510208651photo-title a, #yiv1510208651 div.yiv1510208651photo-title a:active, #yiv1510208651 div.yiv1510208651photo-title a:hover, #yiv1510208651 div.yiv1510208651photo-title a:visited {text-decoration:none;}#yiv1510208651 div#yiv1510208651ygrp-mlmsg #yiv1510208651ygrp-msg p a span.yiv1510208651yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv1510208651 .yiv1510208651green {color:#628c2a;}#yiv1510208651 .yiv1510208651MsoNormal {margin:0 0 0 0;}#yiv1510208651 o {font-size:0;}#yiv1510208651 #yiv1510208651photos div {float:left;width:72px;}#yiv1510208651 #yiv1510208651photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv1510208651 #yiv1510208651photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv1510208651 #yiv1510208651reco-category {font-size:77%;}#yiv1510208651 #yiv1510208651reco-desc {font-size:77%;}#yiv1510208651 .yiv1510208651replbq {margin:4px;}#yiv1510208651 #yiv1510208651ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv1510208651 #yiv1510208651ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv1510208651 #yiv1510208651ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv1510208651 #yiv1510208651ygrp-mlmsg select, #yiv1510208651 input, #yiv1510208651 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv1510208651 #yiv1510208651ygrp-mlmsg pre, #yiv1510208651 code {font:115% monospace;}#yiv1510208651 #yiv1510208651ygrp-mlmsg * {line-height:1.22em;}#yiv1510208651 #yiv1510208651ygrp-mlmsg #yiv1510208651logo {padding-bottom:10px;}#yiv1510208651 #yiv1510208651ygrp-msg p a {font-family:Verdana;}#yiv1510208651 #yiv1510208651ygrp-msg p#yiv1510208651attach-count span {color:#1E66AE;font-weight:700;}#yiv1510208651 #yiv1510208651ygrp-reco #yiv1510208651reco-head {color:#ff7900;font-weight:700;}#yiv1510208651 #yiv1510208651ygrp-reco {margin-bottom:20px;padding:0px;}#yiv1510208651 #yiv1510208651ygrp-sponsor #yiv1510208651ov li a {font-size:130%;text-decoration:none;}#yiv1510208651 #yiv1510208651ygrp-sponsor #yiv1510208651ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv1510208651 #yiv1510208651ygrp-sponsor #yiv1510208651ov ul {margin:0;padding:0 0 0 8px;}#yiv1510208651 #yiv1510208651ygrp-text {font-family:Georgia;}#yiv1510208651 #yiv1510208651ygrp-text p {margin:0 0 1em 0;}#yiv1510208651 #yiv1510208651ygrp-text tt {font-size:120%;}#yiv1510208651 #yiv1510208651ygrp-vital ul li:last-child {border-right:none !important;}#yiv1510208651

 
Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list
Hi Sir I did not get the solution.. Please help me...

Sent from Yahoo Mail on Android

From:"Deepak Achar [hidden email] [OpenCV]" <[hidden email]>
Date:Mon, Mar 30, 2015 at 9:15 PM
Subject:Re: [OpenCV] Saving Multiple Blocks of an image

 

here is a code Sir


#include <iostream>

#include <stdio.h>

#include <stdlib.h>

#include <fstream>



#include <conio.h>

#include "opencv\cvaux.h"

#include "opencv\highgui.h"



#include "opencv2/highgui/highgui.hpp"

#include "opencv2/imgproc/imgproc.hpp"

#include "opencv2/core/core.hpp"


using namespace std;

using namespace cv;


int main( int argc, char** argv )

{

Mat image;

char file[256];

sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");

cvSaveImage(file,1);

 

image = imread("secret_image.tiff",1);

if(image.empty())

{

cout << "Could not open or find the image" << std::endl ;

return -1;

}



namedWindow("Image", CV_WINDOW_AUTOSIZE );

imshow("Image", image);



   // get the image data

 int height = image.rows;

 int width = image.cols;


 printf("Processing a %dx%d image\n",height,width);


cv :: Size smallSize ( 64 , 64 );


std :: vector < Mat > smallImages ;

namedWindow("smallImages", CV_WINDOW_AUTOSIZE );


for  ( int y =  0 ; y < image . rows ; y += smallSize . height )

{

    for  ( int x =  0 ; x < image . cols ; x += smallSize . width )

    {

        cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );

        smallImages . push_back ( cv :: Mat ( image , rect ));

                sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages);

                imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );

        imshow ( "smallImages",cv :: Mat ( image , rect ) );

                waitKey(0);

        }

}

return 0;

                }




On Sunday, 29 March 2015 4:40 PM, "Alrabi opencv [hidden email] [OpenCV]" <[hidden email]> wrote:



 

You can use this piece of code to divide an image into equal blocks. 


int main()

{

        Mat img = imread("1.jpg");

        imshow("original", img);

        waitKey(2000);


        for(int i = 0; i <=img.rows - (img.rows/2); i = i + (img.rows/2))

        {

                for(int j = 0; j <=img.cols - (img.cols/2); j = j + (img.cols/2))

                {

                        Mat sub(img, Rect(j, i, (img.rows/2), (img.rows/2) ));

                        imwrite("sub" + to_string(static_cast<long long>(i)) + to_string(static_cast<long long>(j)) +".jpg",sub);

                }

        }


        system("pause");

        return 0;

}



On Fri, Mar 27, 2015 at 7:48 PM, Deepak Achar [hidden email] [OpenCV] <[hidden email]> wrote:

 

Dear Sir,


Please help in saving blocks of an image in this code after dividing the image in different folder.


#include <iostream>

#include <stdio.h>

#include <stdlib.h>

#include <fstream>



#include <conio.h>

#include "opencv\cvaux.h"

#include "opencv\highgui.h"



#include "opencv2/highgui/highgui.hpp"

#include "opencv2/imgproc/imgproc.hpp"

#include "opencv2/core/core.hpp"


using namespace std;

using namespace cv;


int main( int argc, char** argv )

{

Mat image;

char file[256];

sprintf(file,"%s","/DEEPAK/My Documents/opencvdatabase/result1");

cvSaveImage(file,1);

 

image = imread("secret_image.tiff",1);

if(image.empty())

{

cout << "Could not open or find the image" << std::endl ;

return -1;

}



namedWindow("Image", CV_WINDOW_AUTOSIZE );

imshow("Image", image);



   // get the image data

 int height = image.rows;

 int width = image.cols;


 printf("Processing a %dx%d image\n",height,width);


cv :: Size smallSize ( 64 , 64 );


std :: vector < Mat > smallImages ;

namedWindow("smallImages", CV_WINDOW_AUTOSIZE );


for  ( int y =  0 ; y < image . rows ; y += smallSize . height )

{

    for  ( int x =  0 ; x < image . cols ; x += smallSize . width )

    {

        cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );

        smallImages . push_back ( cv :: Mat ( image , rect ));

                sprintf(file,"%d%d%d_%d%d%d.jpg\n", smallImages);

                imwrite ("smallImages.tiff", cv :: Mat ( image , rect ) );

        imshow ( "smallImages",cv :: Mat ( image , rect ) );

                waitKey(0);

        }

}

return 0;

                }



Thanks and regards

Deepak







Reply | Threaded
Open this post in threaded view
|

Re: Saving Multiple Blocks of an image

opencv-users mailing list
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <math.h>
#include <string.h>
#include <errno.h>

//#include <conio.h> //this does not work on my linux machine

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"


using namespace std;
using namespace cv;

  int main( int argc, char** argv )
    {
      Mat image;
      image = imread("secret_image.tiff",1);
      if(image.empty())
         {
           cout << "Could not open or find the image" << std::endl ;
           return -1;
          }

      namedWindow("Image", CV_WINDOW_AUTOSIZE );
      imshow("Image", image);
   // get the image data

      int height = image.cols;
      int width = image.rows;

      unsigned int imageW_half = (height / 4);
      unsigned int imageH_half = (width / 4);
      printf("Processing a Width and Height of %d X %d images\n",imageW_half, imageH_half);

      for  ( int y =  0 ; y < 2 ; y = y + 1)
          {

        for  ( int x =  0 ; x < 2 ; x = x + 1)

            {

              Mat rect(image, Rect( x * imageW_half, y * imageH_half, imageW_half, imageH_half));

              char fffile [64];
              sprintf(fffile,"/DEEPAK/MyDocuments/opencvdatabase/result1/smallImages_%dw_%dh.tiff", imageWhalfe, imageHhlfe );
 //             sprintf(fffile,"smallImages_%dw_%dh.tiff", x, y);
              namedWindow(fffile, CV_WINDOW_AUTOSIZE );

              imwrite(fffile,rect);
              imshow ( fffile, rect);
             }
         }
  waitKey(0);
  return 0;
 }