remove gradient of a image without a comparison image
Asked Answered
F

2

13

currently i am having much difficulty thinking of a good method of removing the gradient from a image i received.

The image is a picture taken by a microscope camera that has a light glare in the middle. The image has a pattern that goes throughout the image. However i am supposed to remove the light glare on the image created by the camera light.

Unfortunately due to the nature of the camera it is not possible to take a picture on black background with the light to find the gradient distribution. Nor do i have a comparison image that is without the gradient. (note- the location of the light glare will always be consistant when the picture is taken)

In easier terms its like having a photo with a flash in it but i want to get rid of the flash. The only problem is i have no way to obtaining the image without flash to compare to or even obtaining a black image with just the flash on it.

My current thought is conduct edge detection and obtain samples in specific locations away from the edges (due to color difference) and use that to gauge the distribution of gradient since those areas are supposed to have relatively identical colors. However i was wondering if there was a easier and better way to do this.

If needed i will post a example of the image later.

At the moment i have a preferrence of solving this in c++ using opencv if that makes it easier.

thanks in advance for any possible ideas for this problem. If there is another link, tutorial, or post that may solve my problem i would greatly appreciate the post.

enter image description here

as you can tell there is a light thats being shinned on the img as you can tell from the white spot. and the top is lighter than the bottome due to the light the color inside the oval is actually different when the picture is taken in color. However the color between the box and the oval should be consistant. My original idea was to perhaps sample only those areas some how and build a profile that i can utilize to remove the light but i am unsure how effective that would be or if there is a better way

EDIT :

Well i tried out Roger's suggestion and the results were suprisngly good. Using 110 kernel gaussian blurr to find illumination and conducting CLAHE on top of that. (both done in opencv)

enter image description here However my colleage told me that the image doesn't look perfectly uniform and pointed out that around the area where the light used to be is slightly brighter. He suggested trying a selective gaussian blur where the areas above certain threshold pixel values are not blurred while the rest of the image is blurred.

Does anyone have opinions regarding this and perhaps a link, tutorial, or an example of something like this being done? Most of the things i find tend to be selective blur for programs like photoshop and gimp

EDIT2 :

enter image description here

it is difficult to tell with just eyes but i believe i have achieved relatively close uniformization by using a simple plane fitting algorithm.((-A * x - B * y) / C) (x,y,z) where z is the pixel value. I think that this can be improved by utilizing perhaps a sine fitting function? i am unsure. But I am relatively happy with the results. Many thanks to Roger for the great ideas.

I believe using a bunch of pictures and getting the avg would've been another good method (suggested by roger) but Unofruntely i was not able to implement this since i was not supplied with various pictures and the machine is under modification so i was unable to use it.

Fleenor answered 28/7, 2013 at 23:32 Comment(4)
You may be able to try using a Gaussian blur with a very large kernel to transform your image into an approximation of the background gradient. Difficult to say without seeing the image.Nephrectomy
would the distribution by the blur be effective enough to completely create a even brightness distribution throughout the img?Fleenor
I very much like this question and its answers. I posted a similar question (#19036335) a month ago, but the answers here are much better.Jaimeejaimes
If you take an image using a piece of diffuser paper, and then blur it slightly to remove artifacts from the paper, it will give you a rough ground truth of the lighting. You can then remove this using background subtraction like MOG2 with learnRate set to 0.Pouf
N
9

I have done some work in this area previously and found that a large Gaussian blur kernel can produce a reasonable approximation to the background illumination. I will try to get something working on your example image but, in the meantime, here is an example of your image after Gaussian blur with radius 50 pixels, which may help you decide if it's worth progressing.

Blurred

UPDATE

Just playing with this image, you can actually get a reasonable improvement using adaptive histogram equalisation (I used CLAHE) - see comparison below - any use?

CLAHE

I will update this answer with more details as I progress.

Nephrectomy answered 29/7, 2013 at 8:42 Comment(13)
thanks for this info. I will try this tomorrow and see how it works out. But in regards to the size of the blurr isn't it best to have the gaussian blurr as large as possible? or is there a certain sweet spot for optimal values?Fleenor
@Fleenor it's a bit of trial and error really, with your image a 60px radius might be better although you may need to enhance the gradient with e.g. a contrast stretch or you'll water it down too much. It also depends on the algorithm you use for deriving the background profile. Not too much time now, will get back to you soon!Nephrectomy
@Fleenor a possible alternative (CLAHE) added to answer. Comments?Nephrectomy
well i definatly think it is a improvement but i think i am still supposed to make the white spot unnoticeable. This is supposed to be a preprocessing step before running a bunch of algorithms to look for microscopic defects in the image. (sry for the late response i am in south korea at the moment) Perhaps there is something that can be done after CLAHE to achieve perfect uniformity?Fleenor
btw for your example using CLAHE what did you set the threahold limit as?Fleenor
well i tried implementing the CLAHE via opencv functions but it seems like uniformity is quite off unfortunately. Although the shade of gray looks similar the area outside the oval but inside the square should have relatively similar colors. But the color is quite off between the top end and bottom end. Since the processing algorithm afterwards is sensitive to pixel values, i need to find a way to achieve it as best as possible.Fleenor
when i tried my gaussian it did not look like your result on 50 for kernel size but looked similar around size 110. Something i might have done differently?Fleenor
@Fleenor Maybe because I wasn't using OpenCV - I used ImageJ to blur, with a radius of 50 (so kernel size 100) and I used my own CLAHE with a clip limit of 5 and 16x16 tiles. Your idea to reduce illumination effects before CLAHE is probably a good choice.Nephrectomy
made a update on the results. It came out pretty good but i think my superior thinks i can make improvements on this by perhaps using a selective gaussian blur. Blur only areas under a certain threshold pixel values. Any thoughts on how effective this may be? If possible i think he would prefer that it is within 5 pixel difference for error which i think is a bit too demanding.Fleenor
@Fleenor yes, I share your concerns but there's no harm experimenting. You need to blur out the real detail so maybe an adaptive blur that depends on the local variance? So high variance results in more blur and low variance results in less blur. Very difficult not to tailor this to particular image content though - some genuine features could look just like lens flare.Nephrectomy
well based on wat i have been told the light glare being shinned on the image should be identical every single time. So my plan is to find a illumination values that i can just minus against the picture everytime the camera takes a picture in the future. So i just need to tailor against this image only to find illumin value then i dont have to calculate this again.i think that blur based on variance is a good idea to experiment with but how should the kernel size be adjusted in regards to this?Fleenor
@Fleenor ok, I would start with a kernel maybe similar size to the main glare artefact. However, if the glare is really identical - even with different samples - could you average a number of images of different samples to try to isolate the glare?Nephrectomy
well i think im going to to stick wit my result with plane fitting on top of the CLAHE image. Thanks for all the helpFleenor
F
4

I would like to point you to this paper: http://www.cs.berkeley.edu/~ravir/dirtylens.pdf, but, in my opinion, without any sort of calibration/comparison image taken apriori, it is difficult to mine out the ground truth from the flared image.

However, if you are trying to just present the image minus the lens flare, disregarding the actual scientific data behind the flared part, then you switch into the domain of image inpainting. Criminsi's algorithm, as described in this paper: http://research.microsoft.com/pubs/67276/criminisi_tip2004.pdf and explained/simplified in these two links: http://cs.brown.edu/courses/csci1950-g/results/final/eboswort/ http://www.cc.gatech.edu/~sooraj/inpainting/, will do a very good job in restoring texture information to the flared up regions. (If you'd really like to pursue this approach, do mention that. More comprehensive help can be provided for this).

However, given the fact that we're dealing with microscopic data, I doubt if you'd like to lose the scientific data contained in a particular region of an image. In that case, I really think you need to find a workaround to determine the flare model of the flash/light source w.r.t the lens you're using.

I hope someone else can shed more light on this.

Fray answered 29/7, 2013 at 5:17 Comment(2)
P.S: Share the image plz.Fray
unfortunately i can not afford to crop anything out of the img. I must keep everything intact and remove the artificial lightingFleenor

© 2022 - 2024 — McMap. All rights reserved.