降低圖像分辨率函數

/*該函數爲降低圖像分辨率的函數。降低分辨率取數時,相鄰兩個數位置相差decrease個像素,若decrease=1,則表示爲原圖*/  //2018.04.21
void DecreaseResolution(BYTE* pbyIn, BYTE*  pbyOut, tSdkFrameHead* pFrameHead, int *diHeight, int *diWidth, int decrease)   
{
	*diHeight = (pFrameHead->iHeight - 1) / decrease + 1;
	*diWidth = (pFrameHead->iWidth - 1) / decrease + 1;

	for (int j = 0; j < pFrameHead->iHeight;)
	{
		for (int i = 0; i < pFrameHead->iWidth;)
		{
			//*pbyOut = (*(pbyIn + pFrameHead->iWidth * j + i));//一個像素8bit
			//pbyOut++;
			memcpy( pbyOut, pbyIn + pFrameHead->iWidth * 3 * j + 3 * i , 3 );//一個像素24bit
			pbyOut = pbyOut + 3;
			i = i + decrease;
		}
		j = j + decrease;
	}
}
/*該函數爲降低圖像分辨率的函數。降低分辨率取數時,相鄰兩個數位置相差interval個像素,若interval=1,則表示爲原圖*/  //2019.05.28
Mat DecreaseResolution(Mat &src, int interval)
{
	
	int rows = (src.rows - 1) / interval + 1;
	int cols = (src.cols - 1) / interval + 1;
	Mat dst = Mat::zeros(rows, cols, CV_8UC1);
	for (int i = 0; i< dst.rows;i++)
	{
		uchar* datasrc = src.ptr(i*interval);
		uchar* datadst = dst.ptr(i);
		for (int j = 0; j < dst.cols;j++)
		{
			datadst[j] = datasrc[j*interval];
		}
	}
	return dst;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章