从一张影像中批量裁剪子影像

/*
Author:Duyang
Data:  2018.10.25
Object:cutting patches-images from only one satellit image
*/

# define _CRT_SECURE_NO_DEPRECATE
# include<iostream>
# include<opencv.hpp>
# include<string>
# include<stdio.h>
using namespace std;
using namespace cv;
# define image_row 500//define the resolution of row and col;
# define image_col 500
void int_to_str(const int &int_temp, string &string_temp)
{
	stringstream stream;
	stream << int_temp;
	string_temp = stream.str();
}

int main()
{
	Mat source;
	source = imread("C:\\Users\\93970\\Desktop\\conv5x5 300张训练结果\\cut.tif",1);
	string path = "C:\\Users\\93970\\Desktop\\1000x1000\\";//the path of cut images
	string image_name;
	string l,h;//the necessity of int 2 string 
	int num=0;
	for (int H = 1; H <= source.rows / image_row; H++)//the number of patches original image can produce;
	{
		int_to_str(H, h);
		for (int L = 1; L<= source.cols / image_col; L++)//the number of patches original image can produce;
				{
					int_to_str(L, l);
					Mat image(image_row, image_col, CV_8UC3);//creat the NULL images
					for (int row = (H - 1)*image_row; row<H*image_row; row++)
					{
						Vec3b *p1 = image.ptr<Vec3b>(row - (H - 1)*image_row);
						Vec3b *p = source.ptr<Vec3b>(row);
						for (int col = (L - 1)*image_col; col<image_col*L; col++)
						{
							*(p1 + col - (L - 1)*image_col) = *(p + col);
						}
					}
					//imshow(image_name, image);
					//waitKey(0);
					imwrite(path +  h + "_" + l + ".png", image);
					num++;
					printf("第%4d张\n", num);
				}
	}
	printf("共计%d张影像",num);
	getchar();




	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嘟嘟love佳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值