Remove light reflection from the image

Dear All;
I have an image for a transparent pipe but photo has a light reflection on the pipe section which makes white spot which affect affect my analysis, what is the best way to remove it ?

 Accepted Answer

The usual way is to use crossed polarizers. Put one in front of the light source, and another one that rotates in front of the lens. Rotate the lens polarizer until the specular reflections is minimized. It's much better to prevent the problem in the first place like this than to try to repair a poor image.

13 Comments

Thank you However, i have no choice i took the image from another one and i have to deal with it . So, i need a way in matlab to reomve these white spots. i saw away to do that in mathematica by first identfying these white spots and then filter them , how can i do that? Best Regards
Please attach your image and tell me what you want to measure. Maybe the white can be ignored. I don't think you simply want to replace white pixels with black pixels - what good would that do? It's best just to make a mask that says essentially to just ignore the bad parts of your image.
mustafa's "Answer" moved here because it's not an answer:
Dear Image analyst;
Thank you for help
please check the following link, it has same issue that i want to do , he want to remove the light reflection from the apple, he did that in mathematica but i do not know how to do it in matlab. he first identify the white spots and remove them from the image , how can we do this in matlab
Dear Image analyst;
Thank you for help
please check the following link, it has same issue that i want to do , he want to remove the light reflection from the apple, he did that in mathematica but i do not know how to do it in matlab. he first identify the white spots and remove them from the image , how can we do this in matlab
mustafa, he did not "do" it as far as I can see. If you're not going to fix your image capture situation the best you can do is to create a mask to analyze around it, or to fill it in. If you want to fill it in, use my color segmentation routines in my file exchange to find "white" then dilate it one layer, then use roifill() to smear the surrounding colors into it, obliterating the white.
Dear Image Analyst;
Thank you for support .
To make the situation more clear for you , My image is attached and i want to remove this light reflection.
What do you suggest.
Regards
The image is not attached.
Dear Image Analyst;
I am able now to correct this . I have another problem now when i am trying to convert the image to Black and White and i have tried many adaptive threshold algorithms but none of them give me the correct answer. When i checked the histogram of the gray image , i found intensities level are distributed through the whole range from 0 - 255 . as you can see in the image , i want to make red area as white and other as black but i did not get the correct complete conversion using these algorithms even though by changing the tuning parameters.
What do you suggest.
Thanks in advance
How do I know what the "correct" answer should be? Maybe I'd try one of those algorithms that you already did and get a "wrong" answer just like you did.
To convert the red to white, convert the image to hsv with rgb2hsv.
hsv = rgb2hsv(rgbImage);
h = hsv(:,:,1);
s = hsv(:,:,2);
v = hsv(:,:,3);
Then extract the hue channel and threshold to find red, which will probably be around hue values of less than 0.1 and more than 0.9.
binaryImage = h < 0.1 | h > 0.9; % Adjust values as needed.
Then take that binary image you get from thresholding and set the value image to 1
v(binaryImage) = 1;
To set other areas to black (like you asked for), do this
v(~binaryImage) = 0;
Then convert back to rgb with hsv2rgb().
hsv = cat(3, h, s, v); % Use modified v to get new hsv.
rgbImage = hsv2rgb(hsv);
mustafa's "Answer" moved here because it's not an "Answer" to the original question but actually a response to me:
Thank you very much for kind cooperation.
Your code works for this image to some extend but this not my goal. Let me explain it for you in more details:
Suppose that you have two liquids moving in pipe each one with a color , what i want to do it to convert the image to black and white image to calculate the area occupied by each of them. Using global threshold is not appropriate for such noisy image , so, adaptive threshold techniques are prefered for this type of images. I have tried about five algorthims but the conversion is not complete. For example, see the image , you can see that not all red area is converted to white especially at the edges where the red color is very light.
So, how can improve the situation ?
Best Regards
Looks like I did a pretty good job thresholding the hue channel. See attached test.m file below the screenshot. Be sure to change the folder name in the code to your folder and image name. I guess maybe you just needed to adjust your thresholds - can't tell because you didn't share your code.
Thank you very much for kind help. Indeed using HSV color model work very well for this kind of images.
I have run the code , it works well just a small thing , why the text and axis is flipped as shown in the attached image ? which MATLAB version do you use ?
This is a very strange result that I first saw about a month ago on one person's system. It was find for everyone else's. The fix was to change the renderer for the figure. I don't remember what fixed it but it was something like going from OpenGl to zbuffer or painter or something.
set(gcf, 'renderer', 'zbuffer');

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!