From cd9a260bac551b10be7d89828b283603a698e21b Mon Sep 17 00:00:00 2001 From: odebeir Date: Fri, 28 Aug 2015 22:13:40 +0200 Subject: [PATCH 1/4] add gamma correction example --- doc/examples/plot_log_gamma.py | 77 ++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 doc/examples/plot_log_gamma.py diff --git a/doc/examples/plot_log_gamma.py b/doc/examples/plot_log_gamma.py new file mode 100644 index 00000000..03975b7f --- /dev/null +++ b/doc/examples/plot_log_gamma.py @@ -0,0 +1,77 @@ +""" +====================================== +Gamma and log contrast adjustment +====================================== + +This examples adjust image contrast by performing a Gamma and a Logarithmic +correction on the input image. + +""" +import matplotlib +import matplotlib.pyplot as plt +import numpy as np + +from skimage import data, img_as_float +from skimage import exposure + +matplotlib.rcParams['font.size'] = 8 + + +def plot_img_and_hist(img, axes, bins=256): + """Plot an image along with its histogram and cumulative histogram. + + """ + img = img_as_float(img) + ax_img, ax_hist = axes + ax_cdf = ax_hist.twinx() + + # Display image + ax_img.imshow(img, cmap=plt.cm.gray) + ax_img.set_axis_off() + + # Display histogram + ax_hist.hist(img.ravel(), bins=bins, histtype='step', color='black') + ax_hist.ticklabel_format(axis='y', style='scientific', scilimits=(0, 0)) + ax_hist.set_xlabel('Pixel intensity') + ax_hist.set_xlim(0, 1) + ax_hist.set_yticks([]) + + # Display cumulative distribution + img_cdf, bins = exposure.cumulative_distribution(img, bins) + ax_cdf.plot(bins, img_cdf, 'r') + ax_cdf.set_yticks([]) + + return ax_img, ax_hist, ax_cdf + + +# Load an example image +img = data.moon() + +# Gamma +gamma_corrected = exposure.adjust_gamma(img, 2) + +# Logarithmic +logarithmic_corrected = exposure.adjust_log(img, 1) + +# Display results +fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(8, 5)) + +ax_img, ax_hist, ax_cdf = plot_img_and_hist(img, axes[:, 0]) +ax_img.set_title('Low contrast image') + +y_min, y_max = ax_hist.get_ylim() +ax_hist.set_ylabel('Number of pixels') +ax_hist.set_yticks(np.linspace(0, y_max, 5)) + +ax_img, ax_hist, ax_cdf = plot_img_and_hist(gamma_corrected, axes[:, 1]) +ax_img.set_title('Gamma correction') + +ax_img, ax_hist, ax_cdf = plot_img_and_hist(logarithmic_corrected, axes[:, 2]) +ax_img.set_title('Logarithmic correction') + +ax_cdf.set_ylabel('Fraction of total intensity') +ax_cdf.set_yticks(np.linspace(0, 1, 5)) + +# prevent overlap of y-axis labels +fig.subplots_adjust(wspace=0.4) +plt.show() \ No newline at end of file From 014ba261fbebb88bbaf187d8b876e08ab43c8e2a Mon Sep 17 00:00:00 2001 From: odebeir Date: Fri, 28 Aug 2015 22:17:25 +0200 Subject: [PATCH 2/4] add gamma correction example --- doc/examples/plot_log_gamma.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/examples/plot_log_gamma.py b/doc/examples/plot_log_gamma.py index 03975b7f..d2d60149 100644 --- a/doc/examples/plot_log_gamma.py +++ b/doc/examples/plot_log_gamma.py @@ -3,8 +3,8 @@ Gamma and log contrast adjustment ====================================== -This examples adjust image contrast by performing a Gamma and a Logarithmic -correction on the input image. +This example adjusts image contrast by performing a Gamma and a Logarithmic +corrections on the input image. """ import matplotlib From 7046df9d3c74806a750f1f836f5308c810246119 Mon Sep 17 00:00:00 2001 From: odebeir Date: Thu, 3 Sep 2015 20:25:57 +0200 Subject: [PATCH 3/4] typos --- doc/examples/plot_log_gamma.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/examples/plot_log_gamma.py b/doc/examples/plot_log_gamma.py index d2d60149..fd0a6767 100644 --- a/doc/examples/plot_log_gamma.py +++ b/doc/examples/plot_log_gamma.py @@ -1,7 +1,7 @@ """ -====================================== +================================= Gamma and log contrast adjustment -====================================== +================================= This example adjusts image contrast by performing a Gamma and a Logarithmic corrections on the input image. @@ -74,4 +74,4 @@ ax_cdf.set_yticks(np.linspace(0, 1, 5)) # prevent overlap of y-axis labels fig.subplots_adjust(wspace=0.4) -plt.show() \ No newline at end of file +plt.show() From c9cc47a635d92dc5923e6bc382a7712e94185645 Mon Sep 17 00:00:00 2001 From: Olivier Debeir Date: Fri, 4 Sep 2015 17:19:53 +0200 Subject: [PATCH 4/4] typo --- doc/examples/plot_log_gamma.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/examples/plot_log_gamma.py b/doc/examples/plot_log_gamma.py index fd0a6767..04a1edbb 100644 --- a/doc/examples/plot_log_gamma.py +++ b/doc/examples/plot_log_gamma.py @@ -4,7 +4,7 @@ Gamma and log contrast adjustment ================================= This example adjusts image contrast by performing a Gamma and a Logarithmic -corrections on the input image. +correction on the input image. """ import matplotlib