Skip to content

Commit 44b81aa

Browse files
committedJun 12, 2015
added bkg_images and cleaned up directory
1 parent 1eeae2c commit 44b81aa

10 files changed

+80
-800
lines changed
 
Loading
Loading
53.5 KB
Loading

‎scripts/image_analysis/nir_sv/nir_sv_z1.py

-174
This file was deleted.

‎scripts/image_analysis/nir_sv/nir_sv_z1000.py

-202
This file was deleted.

‎scripts/image_analysis/nir_sv/nir_sv_z1_L2.py

-174
This file was deleted.

‎scripts/image_analysis/nir_sv/nir_sv_z2500.py

100755100644
+42-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This is a computational pipeline which uses the plantcv module to sharpen, filter and analyze NIR images
44
# Pipeline designed for use with Setaria plants at zoom X2500
55
# The strategy/methodology is adopted from the textbook "Digital Image Processing" by Gonzalez and Woods
6-
# Version 0.2 Max Feldman 4.6.14
6+
# Version 0.9 Max Feldman 7.29.14
77

88
import argparse
99
import scipy
@@ -37,11 +37,30 @@ def main():
3737
if args.debug:
3838
print("Analyzing your image dude...")
3939
# Read image
40+
device = 0
4041
img = cv2.imread(args.image, flags=0)
42+
path, img_name = os.path.split(args.image)
43+
# Read in image which is average of average of backgrounds
44+
img_bkgrd = cv2.imread("bkgrd_ave_z2500.png", flags=0)
45+
46+
# NIR images for burnin2 are up-side down. This may be fixed in later experiments
47+
img = ndimage.rotate(img, 180)
48+
img_bkgrd = ndimage.rotate(img_bkgrd, 180)
49+
50+
# Subtract the image from the image background to make the plant more prominent
51+
device, bkg_sub_img = pcv.image_subtract(img, img_bkgrd, device, args.debug)
52+
if args.debug:
53+
pcv.plot_hist(bkg_sub_img, 'bkg_sub_img')
54+
device, bkg_sub_thres_img = pcv.binary_threshold(bkg_sub_img, 145, 255, 'dark', device, args.debug)
55+
bkg_sub_thres_img = cv2.inRange(bkg_sub_img, 30, 220)
56+
if args.debug:
57+
cv2.imwrite('bkgrd_sub_thres.png', bkg_sub_thres_img)
58+
59+
#device, bkg_sub_thres_img = pcv.binary_threshold_2_sided(img_bkgrd, 50, 190, device, args.debug)
60+
4161
# if a region of interest is specified read it in
4262
roi = cv2.imread(args.roi)
43-
# Pipeline step
44-
device = 0
63+
4564

4665
# Start by examining the distribution of pixel intensity values
4766
if args.debug:
@@ -107,6 +126,7 @@ def main():
107126
kern[1,0:3]=1
108127
kern[0:3,1]=1
109128

129+
110130
# Perform erosion with 4 small kernels
111131
device, e1_img = pcv.erode(tr_es_img, kern1, 1, device, args.debug)
112132
device, e2_img = pcv.erode(tr_es_img, kern2, 1, device, args.debug)
@@ -119,17 +139,18 @@ def main():
119139
device, c1234_img = pcv.logical_or(c123_img, e4_img, device, args.debug)
120140

121141
# Perform dilation
122-
device, dil_img = pcv.dilate(c1234_img, kern, 1, device, args.debug)
123-
142+
# device, dil_img = pcv.dilate(c1234_img, kern, 1, device, args.debug)
143+
device, comb_img = pcv.logical_or(c1234_img, bkg_sub_thres_img, device, args.debug)
144+
124145
# Get masked image
125146
# The dilated image may contain some pixels which are not plant
126-
device, masked_erd = pcv.apply_mask(img, c1234_img, 'black', device, args.debug)
127-
device, masked_erd_dil = pcv.apply_mask(img, dil_img, 'black', device, args.debug)
147+
device, masked_erd = pcv.apply_mask(img, comb_img, 'black', device, args.debug)
148+
# device, masked_erd_dil = pcv.apply_mask(img, dil_img, 'black', device, args.debug)
128149

129150
# Need to remove the edges of the image, we did that by generating a set of rectangles to mask the edges
130151
# img is (254 X 320)
131152
# mask for the bottom of the image
132-
device, box1_img, rect_contour1, hierarchy1 = pcv.rectangle_mask(img, (1,184), (318,252), device, args.debug)
153+
device, box1_img, rect_contour1, hierarchy1 = pcv.rectangle_mask(img, (120,184), (215,252), device, args.debug)
133154
# mask for the left side of the image
134155
device, box2_img, rect_contour2, hierarchy2 = pcv.rectangle_mask(img, (1,1), (85,252), device, args.debug)
135156
# mask for the right side of the image
@@ -143,29 +164,34 @@ def main():
143164
device, bx1234_img = pcv.logical_or(bx123_img, box4_img, device, args.debug)
144165
device, inv_bx1234_img = pcv.invert(bx1234_img, device, args.debug)
145166

146-
147-
device, inv_box1_img = pcv.invert(box1_img, device, args.debug)
148-
149-
# Lets try the reverse stategy
150167
# Make a ROI around the plant, include connected objects
151168
# Apply the box mask to the image
152169
# device, masked_img = pcv.apply_mask(masked_erd_dil, inv_bx1234_img, 'black', device, args.debug)
153-
device, edge_masked_img = pcv.apply_mask(masked_erd_dil, inv_bx1234_img, 'black', device, args.debug)
170+
171+
device, edge_masked_img = pcv.apply_mask(masked_erd, inv_bx1234_img, 'black', device, args.debug)
172+
154173
device, roi_img, roi_contour, roi_hierarchy = pcv.rectangle_mask(img, (120,75), (200,184), device, args.debug)
174+
155175
plant_objects, plant_hierarchy = cv2.findContours(edge_masked_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
156-
157176
device, roi_objects, hierarchy5, kept_mask, obj_area = pcv.roi_objects(img, 'partial', roi_contour, roi_hierarchy, plant_objects, plant_hierarchy, device, args.debug)
177+
158178

159179
# Apply the box mask to the image
160180
# device, masked_img = pcv.apply_mask(masked_erd_dil, inv_bx1234_img, 'black', device, args.debug)
161181
device, masked_img = pcv.apply_mask(kept_mask, inv_bx1234_img, 'black', device, args.debug)
182+
rgb = cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
162183
# Generate a binary to send to the analysis function
163184
device, mask = pcv.binary_threshold(masked_img, 1, 255, 'light', device, args.debug)
185+
mask3d = np.copy(mask)
186+
plant_objects_2, plant_hierarchy_2 = cv2.findContours(mask3d,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
187+
device, o, m = pcv.object_composition(rgb, roi_objects, hierarchy5, device, args.debug)
164188

165189
### Analysis ###
166-
device, hist_header, hist_data, h_norm = pcv.analyze_NIR_intensity(img, args.image, mask, 256, device, args.debug, args.image)
167-
#device, shape_header, shape_data, ori_img = pcv.analyze_object(img, args.img, roi_objects, mask, device, args.debug, args.image)
190+
device, hist_header, hist_data, h_norm = pcv.analyze_NIR_intensity(img, args.image, mask, 256, device, args.debug, args.outdir + '/' + img_name)
191+
device, shape_header, shape_data, ori_img = pcv.analyze_object(rgb, args.image, o, m, device, args.debug, args.outdir + '/' + img_name)
192+
168193
pcv.print_results(args.image, hist_header, hist_data)
194+
pcv.print_results(args.image, shape_header, shape_data)
169195

170196
if __name__ == '__main__':
171197
main()

‎scripts/image_analysis/nir_sv/nir_sv_z3500.py

100755100644
+23-27
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/python
22

33
# This is a computational pipeline which uses the plantcv module to sharpen, filter and analyze NIR images
4-
# Pipeline designed for use with Setaria plants at zoom X500
4+
# Pipeline designed for use with Setaria plants at zoom X3500
55
# The strategy/methodology is adopted from the textbook "Digital Image Processing" by Gonzalez and Woods
66
# Version 0.9 Max Feldman 7.29.14
77

8-
98
import argparse
109
import scipy
1110
from scipy import ndimage
@@ -27,7 +26,6 @@ def options():
2726
parser.add_argument("-i", "--image", help="Input image file.", required=True)
2827
parser.add_argument("-m", "--roi", help="Input region of interest file.", required=False)
2928
parser.add_argument("-o", "--outdir", help="Output directory for image files.", required=False)
30-
# parser.add_argument("-b", "--bkgrd", help="Image of average pixel intensity of background.", required=True)
3129
parser.add_argument("-D", "--debug", help="Turn on debug, prints intermediate images.", action="store_true")
3230
args = parser.parse_args()
3331
return args
@@ -44,27 +42,26 @@ def main():
4442
img = cv2.imread(args.image, flags=0)
4543
path, img_name = os.path.split(args.image)
4644
# Read in image which is average of average of backgrounds
47-
img_bkgrd = cv2.imread("/home/mgehan/LemnaTec/ddpsc_image_git/docs/background_nir_z3500.png", flags=0)
45+
img_bkgrd = cv2.imread("bkgrd_ave_z3500.png", flags=0)
4846

4947
# NIR images for burnin2 are up-side down. This may be fixed in later experiments
50-
img = ndimage.rotate(img, 0)
51-
img_bkgrd = ndimage.rotate(img_bkgrd, 0)
48+
img = ndimage.rotate(img, 180)
49+
img_bkgrd = ndimage.rotate(img_bkgrd, 180)
5250

5351
# Subtract the image from the image background to make the plant more prominent
5452
device, bkg_sub_img = pcv.image_subtract(img, img_bkgrd, device, args.debug)
5553
if args.debug:
5654
pcv.plot_hist(bkg_sub_img, 'bkg_sub_img')
57-
device, bkg_sub_thres_img = pcv.binary_threshold(bkg_sub_img, 150, 255, 'dark', device, args.debug)
58-
bkg_sub_thres_img = cv2.inRange(bkg_sub_img, 50, 190)
55+
device, bkg_sub_thres_img = pcv.binary_threshold(bkg_sub_img, 145, 255, 'dark', device, args.debug)
56+
bkg_sub_thres_img = cv2.inRange(bkg_sub_img, 30, 220)
5957
if args.debug:
6058
cv2.imwrite('bkgrd_sub_thres.png', bkg_sub_thres_img)
61-
59+
6260
#device, bkg_sub_thres_img = pcv.binary_threshold_2_sided(img_bkgrd, 50, 190, device, args.debug)
63-
61+
6462
# if a region of interest is specified read it in
6563
roi = cv2.imread(args.roi)
66-
67-
64+
6865
# Start by examining the distribution of pixel intensity values
6966
if args.debug:
7067
pcv.plot_hist(img, 'hist_img')
@@ -83,7 +80,7 @@ def main():
8380
device, lp_shrp_img = pcv.image_subtract(img, lp_img, device, args.debug)
8481
if args.debug:
8582
pcv.plot_hist(lp_shrp_img, 'hist_lp_shrp')
86-
83+
8784
# Sobel filtering
8885
# 1st derivative sobel filtering along horizontal axis, kernel = 1, unscaled)
8986
device, sbx_img = pcv.sobel_filter(img, 1, 0, 1, 1, device, args.debug)
@@ -112,7 +109,7 @@ def main():
112109
pcv.plot_hist(edge_shrp_img, 'hist_edge_shrp_img')
113110

114111
# Perform thresholding to generate a binary image
115-
device, tr_es_img = pcv.binary_threshold(edge_shrp_img, 150, 255, 'dark', device, args.debug)
112+
device, tr_es_img = pcv.binary_threshold(edge_shrp_img, 145, 255, 'dark', device, args.debug)
116113

117114
# Prepare a few small kernels for morphological filtering
118115
kern = np.zeros((3,3), dtype=np.uint8)
@@ -129,6 +126,7 @@ def main():
129126
kern[1,0:3]=1
130127
kern[0:3,1]=1
131128

129+
132130
# Perform erosion with 4 small kernels
133131
device, e1_img = pcv.erode(tr_es_img, kern1, 1, device, args.debug)
134132
device, e2_img = pcv.erode(tr_es_img, kern2, 1, device, args.debug)
@@ -151,13 +149,13 @@ def main():
151149

152150
# Need to remove the edges of the image, we did that by generating a set of rectangles to mask the edges
153151
# img is (254 X 320)
154-
152+
155153
# mask for the bottom of the image
156-
device, box1_img, rect_contour1, hierarchy1 = pcv.rectangle_mask(img, (75,212), (250,252), device, args.debug)
154+
device, box1_img, rect_contour1, hierarchy1 = pcv.rectangle_mask(img, (100,210), (230,252), device, args.debug)
157155
# mask for the left side of the image
158-
device, box2_img, rect_contour2, hierarchy2 = pcv.rectangle_mask(img, (1,1), (75,252), device, args.debug)
156+
device, box2_img, rect_contour2, hierarchy2 = pcv.rectangle_mask(img, (1,1), (85,252), device, args.debug)
159157
# mask for the right side of the image
160-
device, box3_img, rect_contour3, hierarchy3 = pcv.rectangle_mask(img, (245,1), (318,252), device, args.debug)
158+
device, box3_img, rect_contour3, hierarchy3 = pcv.rectangle_mask(img, (240,1), (318,252), device, args.debug)
161159
# mask the edges
162160
device, box4_img, rect_contour4, hierarchy4 = pcv.border_mask(img, (1,1), (318,252), device, args.debug)
163161

@@ -167,36 +165,34 @@ def main():
167165
device, bx1234_img = pcv.logical_or(bx123_img, box4_img, device, args.debug)
168166
device, inv_bx1234_img = pcv.invert(bx1234_img, device, args.debug)
169167

168+
170169
# Make a ROI around the plant, include connected objects
171170
# Apply the box mask to the image
172171
# device, masked_img = pcv.apply_mask(masked_erd_dil, inv_bx1234_img, 'black', device, args.debug)
173-
174172
device, edge_masked_img = pcv.apply_mask(masked_erd, inv_bx1234_img, 'black', device, args.debug)
175-
176-
device, roi_img, roi_contour, roi_hierarchy = pcv.rectangle_mask(img, (50,50), (280,215), device, args.debug)
177-
173+
device, roi_img, roi_contour, roi_hierarchy = pcv.rectangle_mask(img, (100,75), (220,208), device, args.debug)
178174
plant_objects, plant_hierarchy = cv2.findContours(edge_masked_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
175+
179176
device, roi_objects, hierarchy5, kept_mask, obj_area = pcv.roi_objects(img, 'partial', roi_contour, roi_hierarchy, plant_objects, plant_hierarchy, device, args.debug)
180177

178+
181179
# Apply the box mask to the image
180+
# device, masked_img = pcv.apply_mask(masked_erd_dil, inv_bx1234_img, 'black', device, args.debug)
182181
device, masked_img = pcv.apply_mask(kept_mask, inv_bx1234_img, 'black', device, args.debug)
183182
rgb = cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
184-
183+
185184
# Generate a binary to send to the analysis function
186185
device, mask = pcv.binary_threshold(masked_img, 1, 255, 'light', device, args.debug)
187186
mask3d = np.copy(mask)
188187
plant_objects_2, plant_hierarchy_2 = cv2.findContours(mask3d,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
189188
device, o, m = pcv.object_composition(rgb, roi_objects, hierarchy5, device, args.debug)
190189

191-
192190
### Analysis ###
193191
device, hist_header, hist_data, h_norm = pcv.analyze_NIR_intensity(img, args.image, mask, 256, device, args.debug, args.outdir + '/' + img_name)
194-
195192
device, shape_header, shape_data, ori_img = pcv.analyze_object(rgb, args.image, o, m, device, args.debug, args.outdir + '/' + img_name)
193+
196194
pcv.print_results(args.image, hist_header, hist_data)
197195
pcv.print_results(args.image, shape_header, shape_data)
198196

199-
200-
201197
if __name__ == '__main__':
202198
main()

‎scripts/image_analysis/nir_sv/nir_sv_z500.py

100755100644
+15-13
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def main():
4444
img = cv2.imread(args.image, flags=0)
4545
path, img_name = os.path.split(args.image)
4646
# Read in image which is average of average of backgrounds
47-
img_bkgrd = cv2.imread("background.png", flags=0)
47+
img_bkgrd = cv2.imread("bkgrd_ave_z500.png", flags=0)
4848

4949
# NIR images for burnin2 are up-side down. This may be fixed in later experiments
50-
img = ndimage.rotate(img, 0)
51-
img_bkgrd = ndimage.rotate(img_bkgrd, 0)
50+
img = ndimage.rotate(img, 180)
51+
img_bkgrd = ndimage.rotate(img_bkgrd, 180)
5252

5353
# Subtract the image from the image background to make the plant more prominent
5454
device, bkg_sub_img = pcv.image_subtract(img, img_bkgrd, device, args.debug)
@@ -58,12 +58,12 @@ def main():
5858
bkg_sub_thres_img = cv2.inRange(bkg_sub_img, 50, 190)
5959
if args.debug:
6060
cv2.imwrite('bkgrd_sub_thres.png', bkg_sub_thres_img)
61-
61+
6262
#device, bkg_sub_thres_img = pcv.binary_threshold_2_sided(img_bkgrd, 50, 190, device, args.debug)
63-
63+
6464
# if a region of interest is specified read it in
6565
roi = cv2.imread(args.roi)
66-
66+
6767

6868
# Start by examining the distribution of pixel intensity values
6969
if args.debug:
@@ -83,7 +83,7 @@ def main():
8383
device, lp_shrp_img = pcv.image_subtract(img, lp_img, device, args.debug)
8484
if args.debug:
8585
pcv.plot_hist(lp_shrp_img, 'hist_lp_shrp')
86-
86+
8787
# Sobel filtering
8888
# 1st derivative sobel filtering along horizontal axis, kernel = 1, unscaled)
8989
device, sbx_img = pcv.sobel_filter(img, 1, 0, 1, 1, device, args.debug)
@@ -112,7 +112,7 @@ def main():
112112
pcv.plot_hist(edge_shrp_img, 'hist_edge_shrp_img')
113113

114114
# Perform thresholding to generate a binary image
115-
device, tr_es_img = pcv.binary_threshold(edge_shrp_img, 132, 255, 'dark', device, args.debug)
115+
device, tr_es_img = pcv.binary_threshold(edge_shrp_img, 145, 255, 'dark', device, args.debug)
116116

117117
# Prepare a few small kernels for morphological filtering
118118
kern = np.zeros((3,3), dtype=np.uint8)
@@ -153,7 +153,7 @@ def main():
153153
# img is (254 X 320)
154154

155155
# mask for the bottom of the image
156-
device, box1_img, rect_contour1, hierarchy1 = pcv.rectangle_mask(img, (128,245), (192,252), device, args.debug)
156+
device, box1_img, rect_contour1, hierarchy1 = pcv.rectangle_mask(img, (128,226), (192,252), device, args.debug)
157157
# mask for the left side of the image
158158
device, box2_img, rect_contour2, hierarchy2 = pcv.rectangle_mask(img, (1,1), (75,252), device, args.debug)
159159
# mask for the right side of the image
@@ -167,13 +167,15 @@ def main():
167167
device, bx1234_img = pcv.logical_or(bx123_img, box4_img, device, args.debug)
168168
device, inv_bx1234_img = pcv.invert(bx1234_img, device, args.debug)
169169

170+
171+
170172
# Make a ROI around the plant, include connected objects
171173
# Apply the box mask to the image
172174
# device, masked_img = pcv.apply_mask(masked_erd_dil, inv_bx1234_img, 'black', device, args.debug)
173-
175+
174176
device, edge_masked_img = pcv.apply_mask(masked_erd, inv_bx1234_img, 'black', device, args.debug)
175-
176-
device, roi_img, roi_contour, roi_hierarchy = pcv.rectangle_mask(img, (120,75), (200,245), device, args.debug)
177+
178+
device, roi_img, roi_contour, roi_hierarchy = pcv.rectangle_mask(img, (120,75), (200,226), device, args.debug)
177179

178180
plant_objects, plant_hierarchy = cv2.findContours(edge_masked_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
179181
device, roi_objects, hierarchy5, kept_mask, obj_area = pcv.roi_objects(img, 'partial', roi_contour, roi_hierarchy, plant_objects, plant_hierarchy, device, args.debug)
@@ -191,7 +193,7 @@ def main():
191193

192194
### Analysis ###
193195
device, hist_header, hist_data, h_norm = pcv.analyze_NIR_intensity(img, args.image, mask, 256, device, args.debug, args.outdir + '/' + img_name)
194-
196+
195197
device, shape_header, shape_data, ori_img = pcv.analyze_object(rgb, args.image, o, m, device, args.debug, args.outdir + '/' + img_name)
196198
pcv.print_results(args.image, hist_header, hist_data)
197199
pcv.print_results(args.image, shape_header, shape_data)

‎scripts/image_analysis/nir_sv/nir_sv_z500_ws.py

-194
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.