Does imdecode return modified image?
Hi guys,
I prepared a grayscale image of dimensions 256x1 and made it contain a gradient of gray (i.e. the left most pixel starts with value 0 (black), the next pixel 1, then 2, 3 and so on until the right most pixel ends with 255 (white)).
When I call imdecode(new Mat(bytes), 6)
on this image I would expect to get back a Mat-object that contains just those values. But instead I get a Mat-object with slightly modified values as if it was filtered by Photoshop through a gradation curve similar to the following one (sorry, I am neither allowed to upload an image nor to publish a link, yet). You'll need to follow the link by copy-paste.
Gradation Curve: http://www.dropbox.com/s/qs6myb5j03i8vfa/opencvForumQuestion0GradationCurve.jpg?dl=0 (www.dropbox.com/s/qs6myb5j03i8vfa/ope...)
Is this intentional (if so why?), is it a bug or am I doing something wrong?
I very much appreciate your help. Thank you.
Kind regards Thomas
I don't think you're using imdecode right. First of all, you should almost never do a new Mat(). Certainly not as a parameter to imdecode.
Second, what format did you save the image as?
is that java ?
and yes, jpeg compression will modify your color ramp ,(it's not really imdecode related)
if you're concerned about this, avoid jpgs, and rather use png
I call it from Java, yes. I tried it with PNG first and got my described results. Then I tried JPG, BMP and even TIF all giving me the same results. I understand, that some algorithm (like JPG for example) does some fancy stuff internally, i.e. when storing the image. But I wouldn't expect it from BMP or TIF.
@all Thank you for your comments @Tetragramm Why should you not call imdecode the way I described? Btw. I am not calling with
new Mat()
as parameter butnew Mat(bytes)
where bytes is an array of bytes (byte[]
), just to make sure I understood you correctly. I found this code in a library called DataVec which can be found here: github.com/deeplearning4j/DataVec The lines of code where the magic happens is in a class calledNativeImageLoader
:I will also file this question in the forum of DataVec but as DataVec directly calls opencv I thought this forum is the right place.
Any idea why this happens?
My apologies, I thought it was C++, not Java.