Commit
·
e55761e
1
Parent(s):
f49b8f8
Upload 2 files
Browse files- filter.ipynb +15 -5
- semanticallysegmentdeezglaciers.ipynb +0 -0
filter.ipynb
CHANGED
@@ -37,8 +37,8 @@
|
|
37 |
}
|
38 |
],
|
39 |
"source": [
|
40 |
-
"if
|
41 |
-
"
|
42 |
"testset = os.listdir(\"secondleg\")[8] # This is for listing out the contents of the folder\n",
|
43 |
"print(testset)\n",
|
44 |
"tiff = Image.open(pl.Path(\n",
|
@@ -61,6 +61,7 @@
|
|
61 |
"outputs": [],
|
62 |
"source": [
|
63 |
"# This is a helper method for chopping up a large glacial scope image into smaller chunks with a width of parameter length and a certain amount of overlap\n",
|
|
|
64 |
"def window_with_remainder(length, overlap, input_size):\n",
|
65 |
" testarray = np.arange(0, input_size)\n",
|
66 |
" return np.vstack((testarray[0:length], np.lib.stride_tricks.sliding_window_view(testarray[len(testarray) % length:], length)[::overlap]))[:, [0, -1]] + [0, 1]"
|
@@ -75,11 +76,12 @@
|
|
75 |
"# This code draws a rectangle from (40,0) to (100, y_surface) in green, and from (40, y_surface) to (100, y_bed) in white.\n",
|
76 |
"# The y_surface and y_bed variables are read from the csv file, and the csv file is read in as a pandas dataframe.\n",
|
77 |
"# The first 5 rows of the csv file are also printed.\n",
|
78 |
-
"# this is done to help calibrate the offsets \n",
|
79 |
"\n",
|
80 |
"testset = os.listdir(\"secondleg\")[10]\n",
|
81 |
"print(testset)\n",
|
82 |
"\n",
|
|
|
83 |
"tiff = Image.open(pl.Path(\n",
|
84 |
" rf'C:\\Users\\aashr\\Desktop\\research\\glaciers\\secondleg\\{testset}\\{testset}.tiff'))\n",
|
85 |
"csv = pd.read_csv(pl.Path(\n",
|
@@ -91,19 +93,27 @@
|
|
91 |
" offset = 0\n",
|
92 |
" else:\n",
|
93 |
" offset = int(offset)\n",
|
|
|
|
|
|
|
94 |
"print(offset)\n",
|
|
|
|
|
95 |
"img = tiff.copy()\n",
|
96 |
"img = img.crop((0,430,img.size[0],1790)) \n",
|
|
|
97 |
"print(csv.head()) # prints first 5 rows of csv file\n",
|
98 |
"csv = csv[[\"x_surface\", \"y_surface\", \"x_bed\", \"y_bed\"]]+offset\n",
|
|
|
99 |
"line = csv.iloc[-1] # gets last row of csv file\n",
|
100 |
"print(csv.head()) # prints first 5 rows of csv file\n",
|
101 |
"\n",
|
102 |
-
"\n",
|
103 |
"draw = ImageDraw.Draw(img)\n",
|
104 |
"draw.rectangle([(40, 0), (100, line[\"y_surface\"])], fill=\"green\") # draws rectangle from (40,0) to (100, y_surface) in green\n",
|
105 |
"draw.rectangle([(40, line[\"y_surface\"]),\n",
|
106 |
-
" (100, line[\"y_bed\"])], fill=\"white\") # draws rectangle from (40, y_surface) to (100, y_bed) in white\n"
|
|
|
107 |
]
|
108 |
},
|
109 |
{
|
|
|
37 |
}
|
38 |
],
|
39 |
"source": [
|
40 |
+
"# This is the first step of the process. Once you have the images and csvs organized in folders with their names, you need to create the offset file that contains the offset. This code creates the offset file if it doesn't exist\n",
|
41 |
+
"\n",
|
42 |
"testset = os.listdir(\"secondleg\")[8] # This is for listing out the contents of the folder\n",
|
43 |
"print(testset)\n",
|
44 |
"tiff = Image.open(pl.Path(\n",
|
|
|
61 |
"outputs": [],
|
62 |
"source": [
|
63 |
"# This is a helper method for chopping up a large glacial scope image into smaller chunks with a width of parameter length and a certain amount of overlap\n",
|
64 |
+
"# Length is the length of the desired chunk, overlap is how much overlap there should be\n",
|
65 |
"def window_with_remainder(length, overlap, input_size):\n",
|
66 |
" testarray = np.arange(0, input_size)\n",
|
67 |
" return np.vstack((testarray[0:length], np.lib.stride_tricks.sliding_window_view(testarray[len(testarray) % length:], length)[::overlap]))[:, [0, -1]] + [0, 1]"
|
|
|
76 |
"# This code draws a rectangle from (40,0) to (100, y_surface) in green, and from (40, y_surface) to (100, y_bed) in white.\n",
|
77 |
"# The y_surface and y_bed variables are read from the csv file, and the csv file is read in as a pandas dataframe.\n",
|
78 |
"# The first 5 rows of the csv file are also printed.\n",
|
79 |
+
"# this is done to help calibrate the offsets by allowing the user to manually calibrate the offset for an image and move through the dataset through altering the listdir line through changing the index\n",
|
80 |
"\n",
|
81 |
"testset = os.listdir(\"secondleg\")[10]\n",
|
82 |
"print(testset)\n",
|
83 |
"\n",
|
84 |
+
"# opens the images, csvs and offset files and reads the needed data\n",
|
85 |
"tiff = Image.open(pl.Path(\n",
|
86 |
" rf'C:\\Users\\aashr\\Desktop\\research\\glaciers\\secondleg\\{testset}\\{testset}.tiff'))\n",
|
87 |
"csv = pd.read_csv(pl.Path(\n",
|
|
|
93 |
" offset = 0\n",
|
94 |
" else:\n",
|
95 |
" offset = int(offset)\n",
|
96 |
+
"\n",
|
97 |
+
"# prints the current offset\n",
|
98 |
+
"\n",
|
99 |
"print(offset)\n",
|
100 |
+
"\n",
|
101 |
+
"# There is no need to open up the entire image, so we make a copy and chop it up\n",
|
102 |
"img = tiff.copy()\n",
|
103 |
"img = img.crop((0,430,img.size[0],1790)) \n",
|
104 |
+
"\n",
|
105 |
"print(csv.head()) # prints first 5 rows of csv file\n",
|
106 |
"csv = csv[[\"x_surface\", \"y_surface\", \"x_bed\", \"y_bed\"]]+offset\n",
|
107 |
+
"# the CSV is backwards, so i am accouting for this and getting up the first mask data point\n",
|
108 |
"line = csv.iloc[-1] # gets last row of csv file\n",
|
109 |
"print(csv.head()) # prints first 5 rows of csv file\n",
|
110 |
"\n",
|
111 |
+
"# creates the image masks and shows the image for calibration\n",
|
112 |
"draw = ImageDraw.Draw(img)\n",
|
113 |
"draw.rectangle([(40, 0), (100, line[\"y_surface\"])], fill=\"green\") # draws rectangle from (40,0) to (100, y_surface) in green\n",
|
114 |
"draw.rectangle([(40, line[\"y_surface\"]),\n",
|
115 |
+
" (100, line[\"y_bed\"])], fill=\"white\") # draws rectangle from (40, y_surface) to (100, y_bed) in white\n",
|
116 |
+
"img.show()"
|
117 |
]
|
118 |
},
|
119 |
{
|
semanticallysegmentdeezglaciers.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|