MATLAB: Im2double, double and adapthisteq

image processingImage Processing ToolboxMATLABpiv

Hello, I'm writing a PIV algorithm, I need to read two grayscale images divide them in interrogation windows and do cross-correlation using xcorr2. I'm having troubles converting the images from uint8 to double: firstly, I don't know if it is better to use double or im2double for converting the images, will corss-correlation give different results? Secondly, I need to do adaptive histogram equalization, if I convert to double using double, before doing it, it produces bad output. If i use im2double instead, it does work; I then think it requires input of type double to be between 0 and 1, I searched the documentation, but it does not say anything about it. I am right? Lastly, is there there any difference if I convert to double before or after the equalization? Thank you very much.

Best Answer

"will corss-correlation give different results"
Yes, since the range of values will be different. Will it matter? For PIV, not at all, since it will just change the scale of all the peaks by the same amount. The location of the peaks will still be the same.
"if I convert to double using double, before doing it, it produces bad output"
Yes, it will. matlab image processing functions expect all double images to be in the range [0,1]. Anything above 1 is considered the same as 1. Therefore a uint8 image converted using double will be in effect an image with black for uint8 0 and white for all intensities between 1 and 255.
So in your case, im2double is better. Note that for a uint8 image, the only thing that im2double does is divide by 255 after conversion to double.