@@ -957,11 +957,50 @@ class VolumeImageViewer {
957957 throw this [ _options ] . errorInterceptor ( error )
958958 }
959959
960+ const ImageFlavors = {
961+ VOLUME : 'VOLUME' ,
962+ LABEL : 'LABEL' ,
963+ OVERVIEW : 'OVERVIEW' ,
964+ THUMBNAIL : 'THUMBNAIL'
965+ }
966+
967+ const hasImageFlavor = ( image , imageFlavor ) => {
968+ return image . ImageType [ 2 ] === imageFlavor
969+ }
970+
971+ /*
972+ * Only include THUMBNAIL image into metadata if no other VOLUME image
973+ * exists with the same resolution
974+ */
975+ const filterImagesByResolution = ( metadata ) => {
976+ const pyramidBaseMetadata = metadata [ metadata . length - 1 ]
977+ const filteredMetadata = metadata . filter ( image => {
978+ if ( hasImageFlavor ( image , ImageFlavors . THUMBNAIL ) ) {
979+ const hasThumbnailEquivalentVolumeImage = metadata . some (
980+ ( img ) =>
981+ hasImageFlavor ( img , ImageFlavors . VOLUME ) &&
982+ pyramidBaseMetadata . TotalPixelMatrixColumns / img . TotalPixelMatrixColumns ===
983+ pyramidBaseMetadata . TotalPixelMatrixColumns / image . TotalPixelMatrixColumns
984+ )
985+ if ( hasThumbnailEquivalentVolumeImage ) {
986+ console . debug ( 'Thumbnail image has equivalent volume image resolution, skipping thumbnail.' , image . SOPInstanceUID )
987+ return false
988+ }
989+ return true
990+ } else {
991+ return true
992+ }
993+ } )
994+
995+ return filteredMetadata
996+ }
997+
960998 // We also accept metadata in raw JSON format for backwards compatibility
961- if ( this [ _options ] . metadata [ 0 ] . SOPClassUID != null ) {
962- this [ _metadata ] = this [ _options ] . metadata
999+ const filteredMetadata = filterImagesByResolution ( this [ _options ] . metadata )
1000+ if ( filteredMetadata [ 0 ] . SOPClassUID != null ) {
1001+ this [ _metadata ] = filteredMetadata
9631002 } else {
964- this [ _metadata ] = this [ _options ] . metadata . map ( instance => {
1003+ this [ _metadata ] = filteredMetadata . map ( instance => {
9651004 return new VLWholeSlideMicroscopyImage ( { metadata : instance } )
9661005 } )
9671006 }
0 commit comments