Skip to content

Commit 43807ec

Browse files
committed
removed unnecessary code
1 parent c3e70ee commit 43807ec

File tree

1 file changed

+0
-356
lines changed

1 file changed

+0
-356
lines changed

napari_cellseg3d/utils.py

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

0 commit comments

Comments
 (0)