Ask Your Question
0

Problem related to image pixel draw in .png format

asked 2013-05-30 20:02:20 -0600

Nihad gravatar image

I have 6 images with 256 by 256 dimension. I want to draw only first image with dimension 100 by 100. Here in my code segment. I tried in following way but failed to draw. How can i do this?

int main(..)
{
............................
 cv::Mat image[6] = cv::Mat::zeros(256, 256, CV_8U);

  for (int i = 0; i < 6; i++) {
    rasterizer.rasterize_depthbuffer(mesh, image[i], i, true);
    std::ostringstream stream;
    stream << i;
    std::string count = stream.str();
    cv::imwrite("image/test" + count + ".png", image[i]);
  }

   for (int y = 0; y < 100; y++) {
      for (int x = 0; x < 100; x++) {
       cv::imwrite("image/test.png", image[0].at<double>(y, x));
      }
    }

}
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-05-31 01:37:17 -0600

If you want to write (on the disk) a part of your image, you should probably used the Region of Interest:

Mat Img = imread( "image/test.jpg" );
Mat subImg = Img(100,100);
imwrite( "myimage.png", subImg );
edit flag offensive delete link more

Comments

2

Or to make it more clear you can first define your region of interest, just as an addition to the code of Mathieu.

 Mat img = imread( "image/test.jpg" );
 Rect region_of_interest = Rect( 0, 0, 100, 100 );
 Mat sub_img = img( region_of_interest );
 imwrite( "image.png", sub_img );
StevenPuttemans gravatar imageStevenPuttemans ( 2013-05-31 03:07:30 -0600 )edit
1

Thnx. It works fine.

Nihad gravatar imageNihad ( 2013-05-31 23:24:03 -0600 )edit
1

answered 2013-05-31 01:35:53 -0600

Siegfried gravatar image

Hi Nihad,

if i understand you correctly you want to downscale the first image in your image array from 256x256 to 100x100.

Then you can use the cv::resize method.

// downscale image
cv::Mat dst;
cv::resize(image[0], dst, cv::Size(100,100));

// write image to png file
cv::imwrite("image/test.png", dst);
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-30 20:02:20 -0600

Seen: 198 times

Last updated: May 31 '13