@@ -601,359 +601,3 @@ def format_Warning(message, category, filename, lineno, line=""):
601601 + str (message )
602602 + "\n "
603603 )
604-
605-
606- def divide_imgs (images ):
607- H = - (- images .shape [1 ] // 412 )
608- W = - (- images .shape [2 ] // 412 )
609-
610- diveded_imgs = np .zeros ((images .shape [0 ] * H * W , 512 , 512 , 1 ), np .float32 )
611- # print(H, W)
612-
613- for z in range (images .shape [0 ]):
614- image = images [z ]
615- for h in range (H ):
616- for w in range (W ):
617- cropped_img = np .zeros ((512 , 512 , 1 ), np .float32 )
618- cropped_img -= 1
619-
620- if images .shape [1 ] < 412 :
621- h = - 1
622- if images .shape [2 ] < 412 :
623- w = - 1
624-
625- if h == - 1 :
626- if w == - 1 :
627- cropped_img [
628- 50 : images .shape [1 ] + 50 ,
629- 50 : images .shape [2 ] + 50 ,
630- 0 ,
631- ] = image [0 : images .shape [1 ], 0 : images .shape [2 ], 0 ]
632- elif w == 0 :
633- cropped_img [
634- 50 : images .shape [1 ] + 50 , 50 :512 , 0
635- ] = image [0 : images .shape [1 ], 0 :462 , 0 ]
636- elif w == W - 1 :
637- cropped_img [
638- 50 : images .shape [1 ] + 50 ,
639- 0 : images .shape [2 ] - 412 * W - 50 ,
640- 0 ,
641- ] = image [
642- 0 : images .shape [1 ],
643- w * 412 - 50 : images .shape [2 ],
644- 0 ,
645- ]
646- else :
647- cropped_img [50 : images .shape [1 ] + 50 , :, 0 ] = image [
648- 0 : images .shape [1 ],
649- w * 412 - 50 : (w + 1 ) * 412 + 50 ,
650- 0 ,
651- ]
652- elif h == 0 :
653- if w == - 1 :
654- cropped_img [
655- 50 :512 , 50 : images .shape [2 ] + 50 , 0
656- ] = image [0 :462 , 0 : images .shape [2 ], 0 ]
657- elif w == 0 :
658- cropped_img [50 :512 , 50 :512 , 0 ] = image [0 :462 , 0 :462 , 0 ]
659- elif w == W - 1 :
660- cropped_img [
661- 50 :512 , 0 : images .shape [2 ] - 412 * W - 50 , 0
662- ] = image [0 :462 , w * 412 - 50 : images .shape [2 ], 0 ]
663- else :
664- # cropped_img[50:512, :, 0] = image[0:462, w*412-50:(w+1)*412+50, 0]
665- try :
666- cropped_img [50 :512 , :, 0 ] = image [
667- 0 :462 , w * 412 - 50 : (w + 1 ) * 412 + 50 , 0
668- ]
669- except :
670- cropped_img [
671- 50 :512 ,
672- 0 : images .shape [2 ] - 412 * (W - 1 ) - 50 ,
673- 0 ,
674- ] = image [
675- 0 :462 , w * 412 - 50 : (w + 1 ) * 412 + 50 , 0
676- ]
677- elif h == H - 1 :
678- if w == - 1 :
679- cropped_img [
680- 0 : images .shape [1 ] - 412 * H - 50 ,
681- 50 : images .shape [2 ] + 50 ,
682- 0 ,
683- ] = image [
684- h * 412 - 50 : images .shape [1 ],
685- 0 : images .shape [2 ],
686- 0 ,
687- ]
688- elif w == 0 :
689- cropped_img [
690- 0 : images .shape [1 ] - 412 * H - 50 , 50 :512 , 0
691- ] = image [h * 412 - 50 : images .shape [1 ], 0 :462 , 0 ]
692- elif w == W - 1 :
693- cropped_img [
694- 0 : images .shape [1 ] - 412 * H - 50 ,
695- 0 : images .shape [2 ] - 412 * W - 50 ,
696- 0 ,
697- ] = image [
698- h * 412 - 50 : images .shape [1 ],
699- w * 412 - 50 : images .shape [2 ],
700- 0 ,
701- ]
702- else :
703- try :
704- cropped_img [
705- 0 : images .shape [1 ] - 412 * H - 50 , :, 0
706- ] = image [
707- h * 412 - 50 : images .shape [1 ],
708- w * 412 - 50 : (w + 1 ) * 412 + 50 ,
709- 0 ,
710- ]
711- except :
712- cropped_img [
713- 0 : images .shape [1 ] - 412 * H - 50 ,
714- 0 : images .shape [2 ] - 412 * (W - 1 ) - 50 ,
715- 0 ,
716- ] = image [
717- h * 412 - 50 : images .shape [1 ],
718- w * 412 - 50 : (w + 1 ) * 412 + 50 ,
719- 0 ,
720- ]
721- else :
722- if w == - 1 :
723- cropped_img [:, 50 : images .shape [2 ] + 50 , 0 ] = image [
724- h * 412 - 50 : (h + 1 ) * 412 + 50 ,
725- 0 : images .shape [2 ],
726- 0 ,
727- ]
728- elif w == 0 :
729- # cropped_img[:, 50:512, 0] = image[h*412-50:(h+1)*412+50, 0:462, 0]
730- try :
731- cropped_img [:, 50 :512 , 0 ] = image [
732- h * 412 - 50 : (h + 1 ) * 412 + 50 , 0 :462 , 0
733- ]
734- except :
735- cropped_img [
736- 0 : images .shape [1 ] - 412 * H - 50 + 412 ,
737- 50 :512 ,
738- 0 ,
739- ] = image [
740- h * 412 - 50 : (h + 1 ) * 412 + 50 , 0 :462 , 0
741- ]
742- elif w == W - 1 :
743- # cropped_img[:, 0:images.shape[2]-412*W-50, 0] = image[h*412-50:(h+1)*412+50, w*412-50:images.shape[2], 0]
744- try :
745- cropped_img [
746- :, 0 : images .shape [2 ] - 412 * W - 50 , 0
747- ] = image [
748- h * 412 - 50 : (h + 1 ) * 412 + 50 ,
749- w * 412 - 50 : images .shape [2 ],
750- 0 ,
751- ]
752- except :
753- cropped_img [
754- 0 : images .shape [1 ] - 412 * H - 50 + 412 ,
755- 0 : images .shape [2 ] - 412 * W - 50 ,
756- 0 ,
757- ] = image [
758- h * 412 - 50 : (h + 1 ) * 412 + 50 ,
759- w * 412 - 50 : images .shape [2 ],
760- 0 ,
761- ]
762- else :
763- # cropped_img[:, :, 0] = image[h*412-50:(h+1)*412+50, w*412-50:(w+1)*412+50, 0]
764- try :
765- cropped_img [:, :, 0 ] = image [
766- h * 412 - 50 : (h + 1 ) * 412 + 50 ,
767- w * 412 - 50 : (w + 1 ) * 412 + 50 ,
768- 0 ,
769- ]
770- except :
771- try :
772- cropped_img [
773- :,
774- 0 : images .shape [2 ] - 412 * (W - 1 ) - 50 ,
775- 0 ,
776- ] = image [
777- h * 412 - 50 : (h + 1 ) * 412 + 50 ,
778- w * 412 - 50 : (w + 1 ) * 412 + 50 ,
779- 0 ,
780- ]
781- except :
782- cropped_img [
783- 0 : images .shape [1 ] - 412 * (H - 1 ) - 50 ,
784- :,
785- 0 ,
786- ] = image [
787- h * 412 - 50 : (h + 1 ) * 412 + 50 ,
788- w * 412 - 50 : (w + 1 ) * 412 + 50 ,
789- 0 ,
790- ]
791- h = max (0 , h )
792- w = max (0 , w )
793- diveded_imgs [z * H * W + w * H + h ] = cropped_img
794- # print(z*H*W+ w*H+h)
795-
796- return diveded_imgs
797-
798-
799- def merge_imgs (imgs , original_image_shape ):
800- merged_imgs = np .zeros (
801- (
802- original_image_shape [0 ],
803- original_image_shape [1 ],
804- original_image_shape [2 ],
805- 1 ,
806- ),
807- np .float32 ,
808- )
809- H = - (- original_image_shape [1 ] // 412 )
810- W = - (- original_image_shape [2 ] // 412 )
811-
812- for z in range (original_image_shape [0 ]):
813- for h in range (H ):
814- for w in range (W ):
815-
816- if original_image_shape [1 ] < 412 :
817- h = - 1
818- if original_image_shape [2 ] < 412 :
819- w = - 1
820-
821- # print(z*H*W+ max(w, 0)*H+max(h, 0))
822- if h == - 1 :
823- if w == - 1 :
824- merged_imgs [
825- z ,
826- 0 : original_image_shape [1 ],
827- 0 : original_image_shape [2 ],
828- 0 ,
829- ] = imgs [z * H * W + 0 * H + 0 ][
830- 50 : original_image_shape [1 ] + 50 ,
831- 50 : original_image_shape [2 ] + 50 ,
832- 0 ,
833- ]
834- elif w == 0 :
835- merged_imgs [
836- z , 0 : original_image_shape [1 ], 0 :412 , 0
837- ] = imgs [z * H * W + w * H + 0 ][
838- 50 : original_image_shape [1 ] + 50 , 50 :462 , 0
839- ]
840- elif w == W - 1 :
841- merged_imgs [
842- z ,
843- 0 : original_image_shape [1 ],
844- w * 412 : original_image_shape [2 ],
845- 0 ,
846- ] = imgs [z * H * W + w * H + 0 ][
847- 50 : original_image_shape [1 ] + 50 ,
848- 50 : original_image_shape [2 ] - 412 * W - 50 ,
849- 0 ,
850- ]
851- else :
852- merged_imgs [
853- z ,
854- 0 : original_image_shape [1 ],
855- w * 412 : (w + 1 ) * 412 ,
856- 0 ,
857- ] = imgs [z * H * W + w * H + 0 ][
858- 50 : original_image_shape [1 ] + 50 , 50 :462 , 0
859- ]
860- elif h == 0 :
861- if w == - 1 :
862- merged_imgs [
863- z , 0 :412 , 0 : original_image_shape [2 ], 0
864- ] = imgs [z * H * W + 0 * H + h ][
865- 50 :462 , 50 : original_image_shape [2 ] + 50 , 0
866- ]
867- elif w == 0 :
868- merged_imgs [z , 0 :412 , 0 :412 , 0 ] = imgs [
869- z * H * W + w * H + h
870- ][50 :462 , 50 :462 , 0 ]
871- elif w == W - 1 :
872- merged_imgs [
873- z , 0 :412 , w * 412 : original_image_shape [2 ], 0
874- ] = imgs [z * H * W + w * H + h ][
875- 50 :462 ,
876- 50 : original_image_shape [2 ] - 412 * W - 50 ,
877- 0 ,
878- ]
879- else :
880- merged_imgs [
881- z , 0 :412 , w * 412 : (w + 1 ) * 412 , 0
882- ] = imgs [z * H * W + w * H + h ][50 :462 , 50 :462 , 0 ]
883- elif h == H - 1 :
884- if w == - 1 :
885- merged_imgs [
886- z ,
887- h * 412 : original_image_shape [1 ],
888- 0 : original_image_shape [2 ],
889- 0 ,
890- ] = imgs [z * H * W + 0 * H + h ][
891- 50 : original_image_shape [1 ] - 412 * H - 50 ,
892- 50 : original_image_shape [2 ] + 50 ,
893- 0 ,
894- ]
895- elif w == 0 :
896- merged_imgs [
897- z , h * 412 : original_image_shape [1 ], 0 :412 , 0
898- ] = imgs [z * H * W + w * H + h ][
899- 50 : original_image_shape [1 ] - 412 * H - 50 ,
900- 50 :462 ,
901- 0 ,
902- ]
903- elif w == W - 1 :
904- merged_imgs [
905- z ,
906- h * 412 : original_image_shape [1 ],
907- w * 412 : original_image_shape [2 ],
908- 0 ,
909- ] = imgs [z * H * W + w * H + h ][
910- 50 : original_image_shape [1 ] - 412 * H - 50 ,
911- 50 : original_image_shape [2 ] - 412 * W - 50 ,
912- 0 ,
913- ]
914- else :
915- merged_imgs [
916- z ,
917- h * 412 : original_image_shape [1 ],
918- w * 412 : (w + 1 ) * 412 ,
919- 0 ,
920- ] = imgs [z * H * W + w * H + h ][
921- 50 : original_image_shape [1 ] - 412 * H - 50 ,
922- 50 :462 ,
923- 0 ,
924- ]
925- else :
926- if w == - 1 :
927- merged_imgs [
928- z ,
929- h * 412 : (h + 1 ) * 412 ,
930- 0 : original_image_shape [2 ],
931- 0 ,
932- ] = imgs [z * H * W + 0 * H + h ][
933- 50 :462 , 50 : original_image_shape [2 ] + 50 , 0
934- ]
935- elif w == 0 :
936- merged_imgs [
937- z , h * 412 : (h + 1 ) * 412 , 0 :412 , 0
938- ] = imgs [z * H * W + w * H + h ][50 :462 , 50 :462 , 0 ]
939- elif w == W - 1 :
940- merged_imgs [
941- z ,
942- h * 412 : (h + 1 ) * 412 ,
943- w * 412 : original_image_shape [2 ],
944- 0 ,
945- ] = imgs [z * H * W + w * H + h ][
946- 50 :462 ,
947- 50 : original_image_shape [2 ] - 412 * W - 50 ,
948- 0 ,
949- ]
950- else :
951- merged_imgs [
952- z ,
953- h * 412 : (h + 1 ) * 412 ,
954- w * 412 : (w + 1 ) * 412 ,
955- 0 ,
956- ] = imgs [z * H * W + w * H + h ][50 :462 , 50 :462 , 0 ]
957-
958- print (merged_imgs .shape )
959- return merged_imgs
0 commit comments