unibas-gravis / scalismo-faces

Scalable Image Analysis and Shape Modelling: Module to work with 2d images, with a focus on face images
Apache License 2.0
118 stars 27 forks source link

Using a small, cropped face image as texture after fitting leads to an image access outside domain error #106

Closed AdamKortylewski closed 6 years ago

AdamKortylewski commented 6 years ago

BUG:

The code crashes when fitting face images where the face is partially outside of the image.

Please change line 45 in TextureExtraction.scala

Some(target(imagePoint.x + 0.5, imagePoint.y + 0.5))

to

Try(target(imagePoint.x + 0.5, imagePoint.y + 0.5)).toOption

Thank you

Andreas-Forster commented 6 years ago

Thanks for reporting this error. I think this is a good solution as invisible points are represented as None when accessing them anyway.

see in imageAsSurfaceProperty

andreas-schneider commented 6 years ago

As an easy fix you can set the AccessMode of the image with

val outsideValue = ???
image.withAccessMode(AccessMode.Padded(outsideValue))

this way the texture will be filled outside the image with outsideValue.

Andreas-Forster commented 6 years ago

This will still be possible if we add the Try-toOption fix. But this fix will prevent future crashing and in my opinion it makes sense.