截取自霧霾檢測(cè)機(jī)

-(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對(duì)象
CGImageRef p_w_picpathRef;
p_w_picpathRef = sourceImage.CGImage;
// 一行有多少個(gè)字節(jié)
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);
//循環(huán)計(jì)算區(qū)域像素點(diǎn)獲得總的梯度值
float sum_grad = 0;
int count = 0;
for (int y = Ypoint; y < Ypoint + Height; y++) {
for (int x = Xpoint; x < Xpoint + Width; x++) {
//計(jì)算周邊8個(gè)點(diǎn)的灰度值
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];
//計(jì)算梯度值
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;
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
當(dāng)前題目:圖像處理并獲取RGB-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://www.chinadenli.net/article44/poghe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、網(wǎng)站維護(hù)、網(wǎng)站策劃、網(wǎng)站收錄、外貿(mào)網(wǎng)站建設(shè)、域名注冊(cè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容
移動(dòng)網(wǎng)站建設(shè)知識(shí)