tga - Targa image – damaged red and green channels -


i've problem 16-bit targa file. i'm opening image , colors weird. it's problem red , green channels – blue fine.

how can repair targa image, on example? (first original image, second must look.)

image

edit: answer gives results look right, won't bit-identical original. weirder going on.

you can make corrupted image out of original image subjecting red , green channels function doubles value, subject wraparound:

f(r) = (r*2) % 255 f(g) = (g*2) % 255 

these functions not invertible, because more 1 input value can map same output value. in particular,

f^-1(r) = {r / 2, r / 2 + 128} 

but can still try recover image if we're willing tolerate errors. we'll try guess whether red (or green) should high; if so, add 128.

two pieces of information can guide our guess:

  1. is blue channel high? unless images contain blue pixels, hint red , green channels should high, too.
  2. is there adjacent pixel red (or green) channel high, while pixel's red channel low (say, less 64)? may suggest both pixels relatively bright, pixel's red channel got wrapped.

i recovered close original image using blue channel information decide between r / 2 , r / 2 + 128, though better using neighboring pixels' red , green channels well.


as side note, 1 way sort of problem occur if there (say) 6 bits of red information, least significant 5 bits retained when file written. useful @ how these images acquired make sure you're not chopping off significant bits of r , g channels somehow.


Comments