颜色空间缩减color space reduction
生活随笔
收集整理的這篇文章主要介紹了
颜色空间缩减color space reduction
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
顏色空間縮減公式? ? ??
//---------------------------------【頭文件、命名空間包含部分】-------------------------- // 描述:包含程序所使用的頭文件和命名空間 //----------------------------------------------------------------------------------------------- #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace std; using namespace cv; //-----------------------------------【全局函數(shù)聲明部分】----------------------------------- // 描述:全局函數(shù)聲明 //----------------------------------------------------------------------------------------------- void colorReduce(Mat& inputImage, Mat& outputImage, int div); void ShowHelpText();//--------------------------------------【main( )函數(shù)】--------------------------------------- // 描述:控制臺應(yīng)用程序的入口函數(shù),我們的程序從這里開始執(zhí)行 //----------------------------------------------------------------------------------------------- int main( ) { //【1】創(chuàng)建原始圖并顯示Mat srcImage = imread("1.jpg"); imshow("原始圖像",srcImage); //【2】按原始圖的參數(shù)規(guī)格來創(chuàng)建創(chuàng)建效果圖Mat dstImage;dstImage.create(srcImage.rows,srcImage.cols,srcImage.type());//效果圖的大小、類型與原圖片相同 ShowHelpText();//【3】記錄起始時間double time0 = static_cast<double>(getTickCount()); //【4】調(diào)用顏色空間縮減函數(shù)colorReduce(srcImage,dstImage,32); //【5】計算運行時間并輸出time0 = ((double)getTickCount() - time0)/getTickFrequency();cout<<"\t此方法運行時間為: "<<time0<<"秒"<<endl; //輸出運行時間//【6】顯示效果圖imshow("效果圖",dstImage); waitKey(0); } //---------------------------------【colorReduce( )函數(shù)】--------------------------------- // 描述:使用【指針訪問:C操作符[ ]】方法版的顏色空間縮減函數(shù) //---------------------------------------------------------------------------------------------- void colorReduce(Mat& inputImage, Mat& outputImage, int div) { //參數(shù)準(zhǔn)備outputImage = inputImage.clone(); //拷貝實參到臨時變量int rowNumber = outputImage.rows; //行數(shù)int colNumber = outputImage.cols*outputImage.channels(); //列數(shù) x 通道數(shù)=每一行元素的個數(shù)//雙重循環(huán),遍歷所有的像素值for(int i = 0;i < rowNumber;i++) //行循環(huán){ uchar* data = outputImage.ptr<uchar>(i); //獲取第i行的首地址for(int j = 0;j < colNumber;j++) //列循環(huán){ // ---------【開始處理每個像素】------------- data[j] = data[j]/div*div + div/2; // ----------【處理結(jié)束】---------------------} //行處理結(jié)束} }?
總結(jié)
以上是生活随笔為你收集整理的颜色空间缩减color space reduction的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 股票回踩10日线意味着什么?
- 下一篇: Split分离通道