Too many changes to show.
To preserve performance only 1000 of 1000+ files are displayed.
1 | +import pandas as pd | ||
2 | +import os | ||
3 | +import csv | ||
4 | + | ||
5 | +file_path = "../../data/MICCAI_BraTS_2019_Data_Training/train_frame_m1" | ||
6 | +csv_name = "../../data/MICCAI_BraTS_2019_Data_Training/train_targets.csv" | ||
7 | + | ||
8 | +f=open(csv_name, 'w', newline='') | ||
9 | +w=csv.writer(f) | ||
10 | +count = 0 | ||
11 | +st = 'BraTS19_2013_10_1' #BraTS19_2013_10_1 | ||
12 | +for path, dirs, files in os.walk(file_path): | ||
13 | + for filename in files: | ||
14 | + print(filename) | ||
15 | + if(filename.split('_seg_flair')[0] != st): | ||
16 | + st = filename.split('_seg_flair')[0] | ||
17 | + count = count + 1 | ||
18 | + w.writerow([filename, count]) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +import cv2 | ||
2 | +import os | ||
3 | +import numpy as np | ||
4 | +import shutil | ||
5 | +import time | ||
6 | + | ||
7 | +font = cv2.FONT_HERSHEY_COMPLEX | ||
8 | + | ||
9 | +load_path = "./total_frame_m1" | ||
10 | +#load_path = "./sample" | ||
11 | +color = (255,255,255) | ||
12 | + | ||
13 | +for path, dirs, files in os.walk(load_path): | ||
14 | + for filename in files: | ||
15 | + img = cv2.imread(os.path.join(path, filename), cv2.IMREAD_GRAYSCALE) | ||
16 | + # (img, threshold_value, value, flag): if pixel val >= threshold_value: pixel_val = value | ||
17 | + _, threshold = cv2.threshold(img, 1, 255, cv2.THRESH_BINARY) | ||
18 | + contours, _ = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) | ||
19 | + | ||
20 | + n_ellipse, n_circle = 0, 0 | ||
21 | + if (len(contours) > 0): | ||
22 | + area = cv2.contourArea(contours[0]) | ||
23 | + largest = "" | ||
24 | + | ||
25 | + for cnt in contours: | ||
26 | + approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cnt, True), True) | ||
27 | + cv2.drawContours(img, [approx], 0, (0), 5) | ||
28 | + x = approx.ravel()[0] | ||
29 | + y = approx.ravel()[1] | ||
30 | + | ||
31 | + #print("approx", len(approx)) | ||
32 | + if len(approx) < 12: | ||
33 | + #cv2.putText(img, "Ellipse", (x, y), font, 1, color) | ||
34 | + n_ellipse = n_ellipse + 1 | ||
35 | + if (area < cv2.contourArea(cnt)): | ||
36 | + area = cv2.contourArea(cnt) | ||
37 | + largest = "e" | ||
38 | + else: | ||
39 | + #cv2.putText(img, "Circle", (x, y), font, 1, color) | ||
40 | + n_circle = n_circle + 1 | ||
41 | + if (area < cv2.contourArea(cnt)): | ||
42 | + area = cv2.contourArea(cnt) | ||
43 | + largest = "c" | ||
44 | + | ||
45 | + print(n_ellipse, n_circle, filename) | ||
46 | + #assert n_ellipse !=0 or n_circle !=0 | ||
47 | + | ||
48 | + if (n_ellipse > n_circle) or (n_ellipse==n_circle and largest == "e"): | ||
49 | + ellipase_path = os.path.join("./ellipse/", filename) | ||
50 | + shutil.copy(os.path.join(path, filename), ellipase_path) | ||
51 | + | ||
52 | + elif (n_ellipse < n_circle) or (n_ellipse==n_circle and largest == "c"): | ||
53 | + circle_path = os.path.join("./circle/", filename) | ||
54 | + shutil.copy(os.path.join(path, filename), circle_path) | ||
55 | + | ||
56 | + elif n_circle == 0 and n_ellipse == 0: | ||
57 | + shutil.copy(os.path.join(path, filename), os.path.join("./zero/", filename)) | ||
58 | + | ||
59 | + | ||
60 | +# cv2.imshow("shapes", img) | ||
61 | +# cv2.imshow("Threshold", threshold) | ||
62 | +# cv2.waitKey(0) | ||
63 | +# cv2.destroyAllWindows() | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +import cv2 | ||
2 | +import numpy as np | ||
3 | + | ||
4 | +font = cv2.FONT_HERSHEY_COMPLEX | ||
5 | + | ||
6 | +#file_path = "../../data/MICCAI_BraTS_2019_Data_Training/train_frame_m1" | ||
7 | + | ||
8 | +# for path, dirs, files in os.walk(file_path): | ||
9 | +# for filename in files: | ||
10 | + | ||
11 | +img = cv2.imread("BraTS19_2013_2_1_seg_flair_8.png", cv2.IMREAD_GRAYSCALE) | ||
12 | + # (img, threshold_value, value, flag): if pixel val >= threshold_value: pixel_val = value | ||
13 | +_, threshold = cv2.threshold(img, 1, 255, cv2.THRESH_BINARY) | ||
14 | +contours, _ = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) | ||
15 | + | ||
16 | +color = (255,255,255) | ||
17 | +n_ellipse, n_circle = 0, 0 | ||
18 | +area = cv2.contourArea(contours[0]) | ||
19 | + | ||
20 | +for cnt in contours: | ||
21 | + approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cnt, True), True) | ||
22 | + cv2.drawContours(img, [approx], 0, (0), 5) | ||
23 | + x = approx.ravel()[0] | ||
24 | + y = approx.ravel()[1] | ||
25 | + | ||
26 | + print(area) | ||
27 | + if (area < cv2.contourArea(cnt)): | ||
28 | + area = cv2.contourArea(cnt) | ||
29 | + | ||
30 | + # ss = "" | ||
31 | + | ||
32 | + # if len(approx) == 3: | ||
33 | + # cv2.putText(img, "Triangle", (x, y), font, 1, color) | ||
34 | + # elif len(approx) == 4: | ||
35 | + # cv2.putText(img, "Rectangle", (x, y), font, 1, color) | ||
36 | + # elif len(approx) == 5: | ||
37 | + # cv2.putText(img, "Pentagon", (x, y), font, 1, color) | ||
38 | + if len(approx) < 12: | ||
39 | + cv2.putText(img, "Ellipse", (x, y), font, 1, color) | ||
40 | + n_ellipse = n_ellipse + 1 | ||
41 | + # if (area < cv2.contourArea(cnt)): | ||
42 | + # area = cv2.contourArea(cnt) | ||
43 | + # ss = "ellipse" | ||
44 | + else: | ||
45 | + cv2.putText(img, "Circle", (x, y), font, 1, color) | ||
46 | + n_circle = n_circle + 1 | ||
47 | + # if (area < cv2.contourArea(cnt)): | ||
48 | + # area = cv2.contourArea(cnt) | ||
49 | + # ss = "circle" | ||
50 | + | ||
51 | +print(n_ellipse, n_circle) | ||
52 | +#print(ss) | ||
53 | + | ||
54 | +cv2.imshow("shapes", img) | ||
55 | +cv2.imshow("Threshold", threshold) | ||
56 | +cv2.waitKey(0) | ||
57 | +cv2.destroyAllWindows() | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
798 Bytes
831 Bytes
446 Bytes
884 Bytes
598 Bytes
458 Bytes
284 Bytes
580 Bytes
799 Bytes
491 Bytes
455 Bytes
960 Bytes
654 Bytes
875 Bytes
992 Bytes
908 Bytes
815 Bytes
692 Bytes
591 Bytes
398 Bytes
564 Bytes
667 Bytes
734 Bytes
810 Bytes
882 Bytes
853 Bytes
708 Bytes
492 Bytes
480 Bytes
794 Bytes
1.93 KB
962 Bytes
1.95 KB
2.09 KB
1.53 KB
2.21 KB
1.33 KB
1.12 KB
561 Bytes
830 Bytes
1.12 KB
1.37 KB
1.43 KB
1.41 KB
1.43 KB
1.33 KB
973 Bytes
2.48 KB
2.65 KB
2.58 KB
2.66 KB
2.54 KB
2.12 KB
1.68 KB
1.16 KB
888 Bytes
754 Bytes
468 Bytes
807 Bytes
697 Bytes
454 Bytes
265 Bytes
827 Bytes
868 Bytes
797 Bytes
491 Bytes
922 Bytes
992 Bytes
648 Bytes
420 Bytes
765 Bytes
368 Bytes
744 Bytes
1009 Bytes
608 Bytes
658 Bytes
804 Bytes
539 Bytes
309 Bytes
728 Bytes
800 Bytes
1001 Bytes
651 Bytes
921 Bytes
943 Bytes
532 Bytes
750 Bytes
467 Bytes
893 Bytes
300 Bytes
769 Bytes
997 Bytes
371 Bytes
569 Bytes
821 Bytes
667 Bytes
835 Bytes
973 Bytes
443 Bytes
736 Bytes
1019 Bytes
951 Bytes
684 Bytes
719 Bytes
280 Bytes
320 Bytes
461 Bytes
973 Bytes
795 Bytes
883 Bytes
951 Bytes
743 Bytes
575 Bytes
724 Bytes
276 Bytes
951 Bytes
694 Bytes
968 Bytes
799 Bytes
717 Bytes
986 Bytes
717 Bytes
217 Bytes
502 Bytes
748 Bytes
1014 Bytes
1002 Bytes
681 Bytes
780 Bytes
517 Bytes
611 Bytes
453 Bytes
714 Bytes
710 Bytes
779 Bytes
682 Bytes
558 Bytes
409 Bytes
267 Bytes
279 Bytes
386 Bytes
971 Bytes
217 Bytes
852 Bytes
652 Bytes
862 Bytes
925 Bytes
763 Bytes
364 Bytes
918 Bytes
375 Bytes
626 Bytes
1000 Bytes
632 Bytes
923 Bytes
740 Bytes
293 Bytes
878 Bytes
547 Bytes
714 Bytes
889 Bytes
825 Bytes
571 Bytes
645 Bytes
704 Bytes
765 Bytes
772 Bytes
728 Bytes
931 Bytes
668 Bytes
557 Bytes
590 Bytes
260 Bytes
727 Bytes
910 Bytes
353 Bytes
783 Bytes
938 Bytes
1005 Bytes
745 Bytes
370 Bytes
371 Bytes
517 Bytes
497 Bytes
789 Bytes
860 Bytes
847 Bytes
823 Bytes
744 Bytes
795 Bytes
656 Bytes
913 Bytes
820 Bytes
415 Bytes
622 Bytes
869 Bytes
760 Bytes
885 Bytes
729 Bytes
942 Bytes
808 Bytes
830 Bytes
355 Bytes
897 Bytes
408 Bytes
503 Bytes
442 Bytes
850 Bytes
860 Bytes
523 Bytes
677 Bytes
624 Bytes
929 Bytes
840 Bytes
807 Bytes
338 Bytes
921 Bytes
866 Bytes
760 Bytes
625 Bytes
641 Bytes
885 Bytes
625 Bytes
523 Bytes
315 Bytes
609 Bytes
780 Bytes
520 Bytes
859 Bytes
471 Bytes
974 Bytes
531 Bytes
714 Bytes
721 Bytes
920 Bytes
827 Bytes
534 Bytes
612 Bytes
331 Bytes
486 Bytes
814 Bytes
515 Bytes
215 Bytes
872 Bytes
739 Bytes
631 Bytes
988 Bytes
948 Bytes
272 Bytes
559 Bytes
550 Bytes
561 Bytes
908 Bytes
675 Bytes
984 Bytes
945 Bytes
931 Bytes
310 Bytes
897 Bytes
953 Bytes
581 Bytes
494 Bytes
802 Bytes
522 Bytes
945 Bytes
575 Bytes
715 Bytes
810 Bytes
891 Bytes
883 Bytes
455 Bytes
666 Bytes
906 Bytes
937 Bytes
657 Bytes
876 Bytes
975 Bytes
1016 Bytes
922 Bytes
836 Bytes
996 Bytes
942 Bytes
980 Bytes
349 Bytes
917 Bytes
763 Bytes
601 Bytes
321 Bytes
467 Bytes
645 Bytes
952 Bytes
774 Bytes
824 Bytes
308 Bytes
1019 Bytes
1019 Bytes
892 Bytes
826 Bytes
993 Bytes
762 Bytes
552 Bytes
878 Bytes
911 Bytes
597 Bytes
842 Bytes
1022 Bytes
962 Bytes
684 Bytes
669 Bytes
986 Bytes
917 Bytes
916 Bytes
660 Bytes
-
Please register or login to post a comment