def plot_scaling_result(template: ImageStack, scaled: ImageStack): f, (before, after) = plt.subplots(ncols=4, nrows=2) for channel, ax in enumerate(before): title = f'Before scaling\nChannel {channel}' intensity_histogram( template, sel={ Axes.CH: channel, Axes.ROUND: 0 }, ax=ax, title=title, log=True, bins=50, ) ax.set_xlim(0, 0.007) for channel, ax in enumerate(after): title = f'After scaling\nChannel {channel}' intensity_histogram( scaled, sel={ Axes.CH: channel, Axes.ROUND: 0 }, ax=ax, title=title, log=True, bins=50, ) f.tight_layout() return f
def plot_intensity_histograms(stack: starfish.ImageStack, r: int, title: str): fig = plt.figure(dpi=150) ax1 = fig.add_subplot(131, title='ch: 0') ax2 = fig.add_subplot(132, title='ch: 1', sharex=ax1, sharey=ax1) ax3 = fig.add_subplot(133, title='ch: 2', sharex=ax1, sharey=ax1) intensity_histogram(stack, sel={ Axes.ROUND: r, Axes.CH: 0 }, log=True, bins=50, ax=ax1) intensity_histogram(stack, sel={ Axes.ROUND: r, Axes.CH: 1 }, log=True, bins=50, ax=ax2) intensity_histogram(stack, sel={ Axes.ROUND: r, Axes.CH: 2 }, log=True, bins=50, ax=ax3) fig.tight_layout() fig.suptitle(title)
def plot_intensity_histograms(ref: starfish.ImageStack, scaled_cr: starfish.ImageStack, scaled_c: starfish.ImageStack, scaled_r: starfish.ImageStack, r: int): fig = plt.figure() ax10 = fig.add_subplot(4, 3, 10) intensity_histogram(scaled_cr, sel={ Axes.ROUND: r, Axes.CH: 0 }, log=True, bins=50, ax=ax10) ax10.set_ylabel('ch and r', rotation=90, size='large') ax11 = fig.add_subplot(4, 3, 11, sharex=ax10) intensity_histogram(scaled_cr, sel={ Axes.ROUND: r, Axes.CH: 1 }, log=True, bins=50, ax=ax11) ax12 = fig.add_subplot(4, 3, 12, sharex=ax10) intensity_histogram(scaled_cr, sel={ Axes.ROUND: r, Axes.CH: 2 }, log=True, bins=50, ax=ax12) ax1 = fig.add_subplot(4, 3, 1, sharex=ax10) intensity_histogram(ref, sel={ Axes.ROUND: r, Axes.CH: 0 }, log=True, bins=50, ax=ax1) ax1.set_title('ch: 0') ax1.set_ylabel('unscaled', rotation=90, size='large') ax2 = fig.add_subplot(4, 3, 2, sharex=ax10) intensity_histogram(ref, sel={ Axes.ROUND: r, Axes.CH: 1 }, log=True, bins=50, ax=ax2) ax2.set_title('ch: 1') ax3 = fig.add_subplot(4, 3, 3, sharex=ax10) intensity_histogram(ref, sel={ Axes.ROUND: r, Axes.CH: 2 }, log=True, bins=50, ax=ax3) ax3.set_title('ch: 2') ax4 = fig.add_subplot(4, 3, 4, sharex=ax10) intensity_histogram(scaled_c, sel={ Axes.ROUND: r, Axes.CH: 0 }, log=True, bins=50, ax=ax4) ax4.set_ylabel('ch', rotation=90, size='large') ax5 = fig.add_subplot(4, 3, 5, sharex=ax10) intensity_histogram(scaled_c, sel={ Axes.ROUND: r, Axes.CH: 1 }, log=True, bins=50, ax=ax5) ax6 = fig.add_subplot(4, 3, 6, sharex=ax10) intensity_histogram(scaled_c, sel={ Axes.ROUND: r, Axes.CH: 2 }, log=True, bins=50, ax=ax6) ax7 = fig.add_subplot(4, 3, 7, sharex=ax10) intensity_histogram(scaled_r, sel={ Axes.ROUND: r, Axes.CH: 0 }, log=True, bins=50, ax=ax7) ax7.set_ylabel('r', rotation=90, size='large') ax8 = fig.add_subplot(4, 3, 8, sharex=ax10) intensity_histogram(scaled_r, sel={ Axes.ROUND: r, Axes.CH: 1 }, log=True, bins=50, ax=ax8) ax9 = fig.add_subplot(4, 3, 9, sharex=ax10) intensity_histogram(scaled_r, sel={ Axes.ROUND: r, Axes.CH: 2 }, log=True, bins=50, ax=ax9) fig.tight_layout()
# the previous example. The intensity histograms for ``Axes.ZPLANE: 2`` and ``Axes.ZPLANE: 8`` # are plotted before and after running :py:class:`.MatchHistograms`. # # ``Axes.ZPLANE: 2`` contains no spots or peaks so the histogram is that of Gaussian noise # # ``Axes.ZPLANE: 8`` has many spots and the histogram shows a long tail of high pixel values # Plot intensity distributions of z-planes from z: 2 and z: 8 before and after scaling import matplotlib import matplotlib.pyplot as plt from starfish.util.plot import intensity_histogram, imshow_plane matplotlib.rcParams["figure.dpi"] = 150 f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2) f.suptitle('Intensity Histograms') intensity_histogram(bs_stack, sel={Axes.ROUND: 0, Axes.CH: 0, Axes.ZPLANE: 2}, log=True, bins=50, ax=ax1, title='Unscaled\nz: 2') intensity_histogram(bs_stack, sel={Axes.ROUND: 0, Axes.CH: 0, Axes.ZPLANE: 8}, log=True, bins=50, ax=ax2, title='Unscaled\nz: 8') intensity_histogram(scaled_z, sel={Axes.ROUND: 0, Axes.CH: 0, Axes.ZPLANE: 2}, log=True, bins=50, ax=ax3, title='Scaled\nz: 2') intensity_histogram(scaled_z, sel={Axes.ROUND: 0, Axes.CH: 0, Axes.ZPLANE: 8}, log=True, bins=50, ax=ax4, title='Scaled\nz: 8') f.tight_layout() #################################################################################################### # As expected, the distributions after scaling are made more similar. The higher values in the # Gaussian noise are shifted higher while the long tail representing high spot intensities is # reduced. Overall the SNR decreased. This does not mean it is never appropriate to # :py:class:`.MatchHistograms` across :py:class:`.Axes.ZPLANE` but any use of # :py:class:`.MatchHistograms` should be done so with caution.
print(stack) # Plot import matplotlib import matplotlib.pyplot as plt from starfish.util.plot import intensity_histogram matplotlib.rcParams["figure.dpi"] = 150 f, (ax1, ax2) = plt.subplots(ncols=2) f.suptitle('Intensity Histogram') # Plot intensity distribution of entire as a histogram with 50 bins intensity_histogram(stack, sel={ Axes.ROUND: 0, Axes.CH: 1 }, log=True, bins=50, ax=ax1, title='Full Image') # Plot intensity distribution of 200x200 pixel ROI with 10 bins intensity_histogram(stack, sel={ Axes.ROUND: 0, Axes.CH: 1, Axes.X: (700, 900), Axes.Y: (100, 300), Axes.ZPLANE: 0 }, log=True,