ios - How to remove color cast or adjust white balance? -


summary:

i've been having issues correcting white balance , color casts on images when testing on iphone 7. far runs fine on iphone 6, camera on 7 creates purple or yellow or blue tint in image flash on. app i'm developing relies heavily on color detection using opencv, i'm trying different methods correct color cast. scenario i'm running this: user has piece of paper , items on paper identify color, when iphone 7 used close paper flash on entire image takes on tint. paper used make easier separate images background, used in white-balance know part of image should white potentially fix white-balance/color cast problems.

details:

i'm able correct slight tints in color using background adjust method opencv:

- (void)adjustbackground:(mat &)inputroi image:(mat &)imageinbg{      scalar meancol = mean(inputroi);      // original     mat laborig, labfloat, roifloat;     std::vector<mat>planes(3);     inputroi.convertto(roifloat, cv_32fc3, 1.0/255.0f);     cvtcolor(roifloat,labfloat,cv_bgr2lab);     split(labfloat,planes);       double l_v,a_v,b_v;     rgb2lab(meancol(2), meancol(1), meancol(0), l_v, a_v, b_v);      add(planes[1], -a_v, planes[1]);     add(planes[2], -b_v, planes[2]);      merge(planes,labfloat);     cvtcolor(labfloat, roifloat, cv_lab2bgr);     roifloat.convertto(inputroi , cv_8uc3, 255.0f);      planes.clear();     laborig.release();     labfloat.release();     roifloat.release(); } 

where rgb2lab implies, converting rgb lab color space. convert image float better precision. able correct small color casts if image heavily tinted still results in tinted colors , color detection opencv still results in of tint color being detected.

what tried next more of direct adjustment of camera settings, feel better approach fixing problem instead of after fact sort of post-processing color correction. found documentation modifying camera's temperature , tint values, results in user having manually adjust sliders desired white-balanced image:

class capturedeviceclass = nsclassfromstring(@"avcapturedevice"); if (capturedeviceclass != nil) {     avcapturedevice *device = [avcapturedevice defaultdevicewithmediatype:avmediatypevideo];     if ([device iswhitebalancemodesupported: avcapturewhitebalancemodelocked]){         if ([device lockforconfiguration:nil]){             avcapturewhitebalancetemperatureandtintvalues temperatureandtint = {             .temperature = tempval,             .tint = tintval,             };          avcapturewhitebalancegains wbgains = [device devicewhitebalancegainsfortemperatureandtintvalues:temperatureandtint];          if((nslocationinrange(wbgains.redgain, nsmakerange(1, (device.maxwhitebalancegain - 1.0))))&&(nslocationinrange(wbgains.greengain, nsmakerange(1, (device.maxwhitebalancegain - 1.0))))&&(nslocationinrange(wbgains.bluegain, nsmakerange(1, (device.maxwhitebalancegain - 1.0)))))         {             nslog(@"good values");             [device devicewhitebalancegainsfortemperatureandtintvalues:temperatureandtint];              [device setwhitebalancemodelockedwithdevicewhitebalancegains:[device devicewhitebalancegainsfortemperatureandtintvalues:temperatureandtint] completionhandler:^(cmtime synctime) {              }];             [device unlockforconfiguration];         }         else{             nslog(@"bad values");         }     } } 

where tempval , tintval inputs sliders.

is there way turn off auto adjustments on iphone camera, or there better way in opencv adjust more extreme color casts?

edit:

here examples. disregard graphs in middle, trying histograms. 1 image shows blue tint on entire image, , other shows color cast correction working in roi in middle, changes colors on image (i need color bands on resistors accurate possible).

http://i.imgur.com/jlc4mda.jpg , http://i.imgur.com/pg81pal.jpg


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -