In [1]:
import matplotlib.pyplot as plt
from bubblekicker.bubblekicker import (BubbleKicker, batchbubblekicker, bubble_properties_calculate,
_bubble_properties_filter, bubble_properties_plot)
from bubblekicker.pipelines import CannyPipeline, AdaptiveThresholdPipeline
In [2]:
%matplotlib inline
In [3]:
img = '3411017m_0004.jpg'
In [4]:
bubbler = CannyPipeline(img, channel='red') #setup the pipeline by loading the file
result = bubbler.run([20, 80], 3, 3, 1, 1) # executing the pipeline with custom parameters
marker_image, props = bubble_properties_calculate(result) # extract the properties
#filtered_bubbles = bubble_properties_filter(props) # filter based on the default filter rules
bubbler.plot();
In [5]:
# the filtered bubbles
plt.imshow(marker_image>0, cmap='gray');
In [6]:
fig, axs = bubble_properties_plot(props, "equivalent_diameter") # make a plot
bubbler.what_have_i_done()
#plt.savefig('BSDhist.png')
In [7]:
#setup the pipeline by loading the file
bubbler = AdaptiveThresholdPipeline(img, channel='red')
result = bubbler.run(191, 15, 2, 3, 1, 1) # executing the pipeline with custom parameters
bubbler.plot() # plot detected bubbbles
marker_image, props = bubble_properties_calculate(result) # extract the properties
## nbubbles, to include
In [8]:
# the filtered bubbles
plt.imshow(marker_image>0, cmap='gray');
In [9]:
#plt.imshow(marker_image, cmap='Greys', interpolation='nearest')
fig, axs = bubble_properties_plot(props, "equivalent_diameter") # make a plot
bubbler.what_have_i_done()
In [10]:
bubbler = BubbleKicker(img, channel='red')
bubbler.edge_detect_canny_opencv([20, 80]) # canny edge detection givin the two parameters to build the gaussian
bubbler.dilate_opencv(3) # dilate using opencv function
bubbler.plot();
bubbler.what_have_i_done()
we can see that too many edges are detected
In [115]:
bubbler.reset_to_raw()
bubbler.edge_detect_canny_opencv([120, 20])
bubbler.dilate_opencv(3)
bubbler.clear_border_skimage(3, 1)
bubbler.plot();
bubbler.what_have_i_done()
plt.savefig('cannyPipeline.jpg')
In [116]:
bubbler.reset_to_raw() # here we are running things in default mode
bubbler.adaptive_threshold_opencv(401, 10)
bubbler.clear_border_skimage()
bubbler.plot()
bubbler.what_have_i_done()
In [76]:
res = batchbubblekicker('sample_images', 'red',
AdaptiveThresholdPipeline,
401, 10, 3, 1, 1)
In [84]:
bubbler = CannyPipeline(img, channel='red')
result = bubbler.run([120, 180], 3, 3, 1, 1)
marker_image, props = bubble_properties_calculate(result) #output do add nbubbles,
#print(nbubbles)
fig, axs = bubble_properties_plot(props, "equivalent_diameter")
In [85]:
props.head()
Out[85]:
In [86]:
# derive and PLOT the bubble properties as a table with no filter
bubbler = CannyPipeline(img, channel='red')
result = bubbler.run([120, 180], 3, 3, 1, 1)
id_image, props = bubble_properties_calculate(result, rules={})
fig, axs = bubble_properties_plot(props, "equivalent_diameter")
#fig.savefig("examples/output_eq_diameter.png")
fig, axs = bubble_properties_plot(props, "area")
#fig.savefig("examples/output_area.png")
In [87]:
# filter bubble properties based on CUSTOM filter ruleset
custom_filter = {'circularity_reciprocal': {'min': 0.2, 'max': 1.6},
'convexity': {'min': 1.92}}
bubbler = CannyPipeline('0325097m_0305.tif', channel='red')
result = bubbler.run([120, 180], 3, 3, 1, 1)
id_image, props = bubble_properties_calculate(result, rules=custom_filter)
print(props.head())
fig, axs = bubble_properties_plot(props, "equivalent_diameter")
plt.show()