Refactoring ImageRecordWriters using generics.