OpenCV编辑单个频段并重新合并

时间:2018-06-06 19:07:47

标签: c++ opencv image-processing rgb

我有一个图像,我将其分成三个独立的通道(b,g,r)。我想操纵红色带,然后重新合并到蓝色和绿色带重新构图。然而,我的功能一直在中止。 RBandSlider是指用于轨道栏的全局int,默认为1.问题几乎是ImageEnhancement函数内的。

我是否需要将redBandsAdjsuted定义为其他内容,还是我没有抓取本地像素并正确重写?

Mat ImageEnhancement(Mat band){
Mat adjustedBand;
Scalar mean, std;
meanStdDev(band, mean , std);
int pixel,temp;
for(int i = 0; i < band.rows;i++){
    for(int j = 0; j < band.cols;j++){
        //extract pixel
        pixel = band.at<Vec3b>(i,j)[0];
        //pixel greater than mean
        if ( pixel > mean[0]){
            temp = (255);
            adjustedBand.at<Vec3b>(i,j) = temp;
        }
        else{
            temp = 0;
            adjustedBand.at<Vec3b>(i,j) = temp ;
        }
    }
}
return adjustedBand;
}


Mat Bands[3],merged,redBandsAdjusted(image.cols,image.rows,CV_8UC1),result;
split(image, Bands);

//loop the echancement adjustment
while(true){


    //adjust red band and merge
    redBandsAdjusted = ImageEnhancement(Bands[2]);
    vector<Mat> channels = {Bands[0],Bands[1],redBandsAdjusted};
    merge(channels,merged);

}

1 个答案:

答案 0 :(得分:1)

当你这样做时:

Mat adjustedBand;

您将从CV_8UC3图像(Mat adjustedBand(band.rows, band.cols, CV_8UC1);)获得3张CV_8U图像(pixel = band.at<Vec3b>(i,j)[0];)。到目前为止,一切都很好。然后你去调整并做2个错误:

  1. adjustedBand.at<Vec3b>(i,j) = temp;永远不会被初始化...您可以uchar执行或在稍后阶段初始化。

  2. adjustedBand.at<uchar>(i,j) = temp;SET SERVEROUTPUT ON; CREATE OR REPLACE PROCEDURE custdets (in_number IN customers.c_ID%TYPE) IS CURSOR customer_cursor IS SELECT c_ID, C_PH, c_FName, c_LName, c_address1, c_address2, c_address3 FROM customers WHERE in_number = c_id; crow customer_cursor%ROWTYPE; BEGIN FOR crow IN customer_cursor LOOP DBMS_OUTPUT.PUT_LINE ('Customer Details'); DBMS_OUTPUT.PUT_LINE ( 'CUST ID#: ' || crow.c_id || CHR (9) || 'PH: ' || crow.c_ph); DBMS_OUTPUT.PUT_LINE ( 'Customer Name: ' || crow.c_Fname || ',' || crow.c_Lname); DBMS_OUTPUT.PUT_LINE ( 'Address: ' || crow.c_address1 || ',' || crow.c_address2 || ',' || crow.c_address3); END LOOP; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE (SQLERRM); END; / 用于操作3个通道而非1个通道图像。您需要使用CREATE OR REPLACE PROCEDURE SalePurchase(in_invoice IN sales_purchases.sp_invoice%TYPE) IS BEGIN DBMS_OUTPUT.PUT_LINE('###########################################'); DBMS_OUTPUT.PUT_LINE('# P U R H A S E - S A L E - S U M M A R Y #'); DBMS_OUTPUT.PUT_LINE('# INVOICE NO: ' || in_invoice || ' #'); DBMS_OUTPUT.PUT_LINE(chr(13)); DBMS_OUTPUT.PUT_LINE('###########################################'); DBMS_OUTPUT.PUT_LINE(CHR(13)); DBMS_OUTPUT.PUT_LINE('############################################'); custdets(); end; / ,例如:mLayout.removeViewAt(mLayout.getChildCount()-1);

  3. 这些是我看到的错误...修复它们并尝试使用调试器,这样你知道某些东西是否正确初始化或者它是否正确操作