91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

圖像處理并獲取RGB

發布時間:2020-07-22 13:41:28 來源:網絡 閱讀:476 作者:卓行天下 欄目:開發技術

截取自霧霾檢測機

-(float) returnGrayVale:(UInt8*)buffer withBytesPerRow:(size_t)bytesPerRow withX:(int)x withY:(int)y{

    UInt8*  tmp;

    tmp = buffer + y * bytesPerRow + x * 4; // RGBAの4つ値をもっているので、1ピクセルごとに*4してずらす

    

    // 獲取圖像的RGB

    UInt8 red,green,blue;

    red = *(tmp + 0);

    green = *(tmp + 1);

    blue = *(tmp + 2);

    

    //獲取灰度值

    float grayValue = [self returnGrayValueWithRGB:red withGreen:green withBlue:blue];

    return grayValue;

}

-(float)ClearIndexBySobel:(UIImage*)sourceImage fromX:(int)Xpoint fromY:(int)Ypoint zoneWidth:(int)Width zoneHeihgt:(int)Height{

    

    int p_w_picpathWidth = sourceImage.size.width;

    int p_w_picpathHeight = sourceImage.size.height;

    

    //防止越界處理

    if (Xpoint<=0 || Xpoint>=p_w_picpathWidth-1 || Ypoint<=0 || Ypoint>=p_w_picpathHeight-1) {

        return -1;

    }

    

    

    //獲取ref對象

    CGImageRef  p_w_picpathRef;

    p_w_picpathRef = sourceImage.CGImage;

    

    // 一行有多少個字節

    size_t                  bytesPerRow;

    bytesPerRow = CGImageGetBytesPerRow(p_w_picpathRef);

    

    CGDataProviderRef   dataProvider;

    dataProvider = CGImageGetDataProvider(p_w_picpathRef);

    

    CFDataRef   data;

    UInt8*      buffer;

    data = CGDataProviderCopyData(dataProvider);

    buffer = (UInt8*)CFDataGetBytePtr(data);

    //循環計算區域像素點獲得總的梯度值

    float sum_grad = 0;

    int count = 0;

    for (int y = Ypoint; y < Ypoint + Height; y++) {

        for (int x = Xpoint; x < Xpoint + Width; x++) {

            

            //計算周邊8個點的灰度值

            float gray_00 = [self returnGrayVale:buffer withBytesPerRow:bytesPerRow withX:x-1 withY:y-1];

            float gray_01 = [self returnGrayVale:buffer withBytesPerRow:bytesPerRow withX:x-1 withY:y];

            float gray_02 = [self returnGrayVale:buffer withBytesPerRow:bytesPerRow withX:x-1 withY:y+1];

            

            float gray_10 = [self returnGrayVale:buffer withBytesPerRow:bytesPerRow withX:x withY:y-1];

            float gray_12 = [self returnGrayVale:buffer withBytesPerRow:bytesPerRow withX:x withY:y+1];

            

            float gray_20 = [self returnGrayVale:buffer withBytesPerRow:bytesPerRow withX:x+1 withY:y-1];

            float gray_21 = [self returnGrayVale:buffer withBytesPerRow:bytesPerRow withX:x+1 withY:y];

            float gray_22 = [self returnGrayVale:buffer withBytesPerRow:bytesPerRow withX:x+1 withY:y+1];

            

            //計算梯度值

            float grad_x = gray_00-gray_02+2*gray_10-2*gray_12+gray_20-gray_22;

            float grad_y = gray_00+2*gray_01+gray_02-gray_20-2*gray_21-gray_22;

            

            float grad=sqrt(grad_x*grad_x+grad_y*grad_y);

            sum_grad +=grad;

            count++;

        }

    }

    

    if(count<=0){

        return 0;

    }

    

    float clearIndex = sum_grad / count;

    

    dataProvider = nil;

    data = nil;

    buffer = nil;

    

    return clearIndex;

}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

二连浩特市| 双牌县| 武清区| 合江县| 鄂尔多斯市| 安多县| 五原县| 汉川市| 曲水县| 罗城| 彭阳县| 福建省| 建始县| 织金县| 南木林县| 江口县| 咸宁市| 木兰县| 比如县| 砀山县| 河北省| 龙岩市| 射阳县| 房山区| 平远县| 舟山市| 渭源县| 滦南县| 葫芦岛市| 沂源县| 海南省| 青海省| 凤城市| 三亚市| 浏阳市| 林周县| 永仁县| 大姚县| 墨玉县| 大城县| 张掖市|