我想爲我的iPhone應用程序中顯示的UIImage實現「自動水平」選項。在我嘗試自己實現它之前,我想知道是否應該使用API中的任何圖像處理方法,用於直方圖等。或者,我應該只抓取底層的CGImage並處理它? (我是新來的iPhone開發。)UIImage - 實現自動水平算法
感謝
MV
我想爲我的iPhone應用程序中顯示的UIImage實現「自動水平」選項。在我嘗試自己實現它之前,我想知道是否應該使用API中的任何圖像處理方法,用於直方圖等。或者,我應該只抓取底層的CGImage並處理它? (我是新來的iPhone開發。)UIImage - 實現自動水平算法
感謝
MV
一個非常簡單的方法是使用一個CGImageRef的解碼陣列,但這隻能幫助一個範圍映射(無γ,等)
const CGFloat decode[6] = {blackPoint,whitePoint,blackPoint,whitePoint,blackPoint,whitePoint};
decodedImage = CGImageCreate(CGImageGetWidth(origImage),
CGImageGetHeight(origImage),
CGImageGetBitsPerComponent(origImage),
CGImageGetBitsPerPixel(origImage),
CGImageGetBytesPerRow(origImage),
CGImageGetColorSpace(origImage),
CGImageGetBitmapInfo(origImage),
CGImageGetDataProvider(origImage),
decode,
YES,
CGImageGetRenderingIntent(origImage)
);
其中白點爲0.0和之間的浮1.0,它決定了哪個亮度將映射到輸出中的純白色,並且blackPoint也是一個浮點,它決定哪個亮度映射到純黑色。
解碼陣列的元素對應於色彩空間的組件,因此此代碼僅適用於RBG圖像。您可以將組件設置爲不同的白色和黑色值,以創建簡單的顏色校正。
就可以計算出白點以及具有以下功能的黑點(W/O色彩校正):
void CalculateAutocorretionValues(CGImageRef image, CGFloat *whitePoint, CGFloat *blackPoint) {
UInt8* imageData = malloc(100 * 100 * 4);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(imageData, 100, 100, 8, 4 * 100, colorSpace, kCGImageAlphaNoneSkipLast);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(ctx, CGRectMake(0, 0, 100, 100), image);
int histogramm[256];
bzero(histogramm, 256 * sizeof(int));
for (int i = 0; i < 100 * 100 * 4; i += 4) {
UInt8 value = (imageData[i] + imageData[i+1] + imageData[i+2])/3;
histogramm[value]++;
}
CGContextRelease(ctx);
free(imageData);
int black = 0;
int counter = 0;
// count up to 200 (2%) values from the black side of the histogramm to find the black point
while ((counter < 200) && (black < 256)) {
counter += histogramm[black];
black ++;
}
int white = 255;
counter = 0;
// count up to 200 (2%) values from the white side of the histogramm to find the white point
while ((counter < 200) && (white > 0)) {
counter += histogramm[white];
white --;
}
*blackPoint = 0.0 - (black/256.0);
*whitePoint = 1.0 + ((255-white)/256.0);
}
我不認爲有現有的API,做圖像處理,但我敢肯定有第三方庫那裏。
這就解釋了自動電平(即,直方圖均衡化)非常好:
http://www.generation5.org/content/2004/histogramEqualization.asp
他們也有Java實現相同的。
呃,什麼是汽車級別? – vodkhang 2010-07-19 06:12:45
「自動色階」是大多數圖像編輯程序(如Photoshop)中的一個選項,可改善圖像的色調範圍。 – 2010-07-19 08:41:17
這看起來很有希望: http://code.google.com/p/simple-iphone-image-processing/ – 2010-07-28 08:42:12