Exemplo n.º 1
0
from Neph_Functions import Image_Subtract
import matplotlib.pyplot as plt
import cv2
import numpy as np

# note try to only use cv2 and numpy as it allows for use of numpy analysis/ indexing

#subtract two images setting images as variables
Image_1_Path = '/home/austen/media/winshare/Groups/Smith_G/austen/Projects/Nephelometry/Polar Nephelometer/Data/05-11-2018/N2_Analysis/im_avg_N2_10s.png'
Image_2_Path = '/home/austen/media/winshare/Groups/Smith_G/austen/Projects/Nephelometry/Polar Nephelometer/Data/05-11-2018/He_Analysis/im_avg_He_10s.png'
Image_1 = cv2.imread(Image_1_Path, 0)
#plt.imshow(Image_1, cmap='gray')
#plt.show()
Image_2 = cv2.imread(Image_2_Path, 0)
#plt.imshow(Image_2, cmap='gray')
#plt.show()

#calling the function and showing the resultant subtracted image
Diff_Image = Image_Subtract(Image_1, Image_2)
plt.imshow(Diff_Image, cmap='gray')
plt.show()

#save particle scattering image (particle scattering = total scattering - rayleigh scattering (n2 or He))
cv2.imwrite('/home/austen/Documents/im_avg_N2subHe.png', Diff_Image)
Exemplo n.º 2
0
# number of files in directory
num_files = len(file_list)
print(num_files)
# loop average of images (cannot sum due to the fact that everything is 8 bit, averaging mitigates overflow)
# the L in Image.fromarray means its grayscale
B = cv2.imread(Path_bkg, 0)
plt.imshow(B, cmap='gray')
plt.show()
#B = B.astype('int')
#B8 = B.astype('uint8')
for counter, fn in enumerate(file_list):
    if counter >= 0 and fn != 'Thumbs.db':
        print(str(fn))
        A = cv2.imread(Path + '/' + str(fn), 0)
        #A = A.astype('int')
        C = Image_Subtract(A, B)
        DI = C.astype('uint8')

        # creates directory for difference images and saves them to it
        if not os.path.exists(Path_PD + '/Images_Bkg_Sub'):
            os.makedirs(Path_PD + '/Images_Bkg_Sub')
        cv2.imwrite(Path_PD + '/Images_Bkg_Sub/' + 'diff_' + str(counter) + '.png', DI)

        # creates directory for heatmaps and saves them to it
        if not os.path.exists(Path_PD + '/Heatmaps'):
            os.makedirs(Path_PD + '/Heatmaps')
        Image_Heatmaps(B, DI, 255, Path_PD + '/Heatmaps/HM_' + str(counter) + '.png')
        rows_DF, cols_DF, int_DF = Profiles(DI, col_boundary_1, col_boundary_2, numrows, numcols, row_boundary_1, row_boundary_2)
        fitxdata1, fitydata1, fyd1, ft, bt, mt, st, bkgt, aug_array, aug_array_norm, tt_smooth, tb_smooth = Curve_Fit_Profiles(gaussian, quadratic, rows_DF, int_DF, cols_DF)

        # here we are plotting the fit data
Exemplo n.º 3
0
im_f2 = ax2.imshow(im_N2Avg, cmap='gray')
# create an axes on the right side of ax. The width of cax will be 5%
# of ax and the padding between cax and ax will be fixed at 0.05 inch.
divider = make_axes_locatable(ax2)
cax = divider.append_axes("right", size="5%", pad=0.05)
f2.colorbar(im_f2, cax=cax)
plt.savefig(Path_Save + '/Nitrogen_Averaged.pdf', format='pdf')
plt.show()
'''
# I think I can eliminate this
# writes image to new file
cv2.imwrite(Path_Save + '/Sample.png', imAvg)
im = cv2.imread(Path_Save + '/Sample.png', 0)
'''
# Background subtraction, not ready to do this yet this belongs below
imRes = Image_Subtract(im, imBKG)
'''
# I think I can eliminate this
# writes image to new file
cv2.imwrite(Path_Save + '/Sample_Background_Subtracted.png', imRes)
im_Res = cv2.imread(Path_Save + '/Sample_Background_Subtracted.png', 0)
'''
'''
# plot of the N2 corrected (helium and bkg) subtracted data
f3, ax3 = plt.subplots()
im_f3 = ax3.imshow(imRes, cmap='gray')
# create an axes on the right side of ax. The width of cax will be 5%
# of ax and the padding between cax and ax will be fixed at 0.05 inch.
divider = make_axes_locatable(ax3)
cax = divider.append_axes("right", size="5%", pad=0.05)
f3.colorbar(im_f3, cax=cax)
# averaging background images
im_SampAvg = Loop_Image_Average(Path_Samp_Dir)
im_N2Avg = Loop_Image_Average(Path_N2_Dir)
im_HeAvg = Loop_Image_Average(Path_He_Dir)
im_BKGAvg = Loop_Image_Average(Path_BKG_Dir)
#im_DarkAvg = Loop_Image_Average(Path_Dark_Dir)

# writes image to new file
#cv2.imwrite(Path_Save + '/Dark_Avg.BMP', im_DarkAvg)
cv2.imwrite(Path_Save + '/BKG_Avg.BMP', im_BKGAvg)
cv2.imwrite(Path_Save + '/He_Avg.BMP', im_HeAvg)
cv2.imwrite(Path_Save + '/N2_Avg.BMP', im_N2Avg)
cv2.imwrite(Path_Save + '/Samp_Avg.BMP', im_SampAvg)

# start subtractions for N2 Rayleigh scattering and sample scattering, this is predominantly for pretty pictures only!
im_Helium_Corrected = Image_Subtract(im_HeAvg, im_BKGAvg) # pure helium scattering and light hitting walls; in theory the thermal background is subtracted
im_N2Rayleigh = Image_Subtract(im_N2Avg, im_HeAvg) # this subtracts the helium scattering, the light hitting walls, and thermal background; in theory leaving pure nitrogen scattering
im_Sample = Image_Subtract(im_SampAvg, im_N2Avg) # this subtracts the nitrogen scattering, the light hitting walls, and thermal background; in theory this leaves pure sample particle scattering

# writes pretty images to new file
cv2.imwrite(Path_Save + '/He_Avg_Corrected.BMP', im_Helium_Corrected)
cv2.imwrite(Path_Save + '/N2_Avg_Corrected.BMP', im_N2Rayleigh)
cv2.imwrite(Path_Save + '/Samp_Avg_Corrected.BMP', im_Sample)


# Initial boundaries on the image , cols can be: [250, 1040], [300, 1040], [405, 887]
rows = [200, 600]
cols = [250, 1050]
cols_array = (np.arange(cols[0], cols[1], 1)).astype(int)
#ROI = im[rows[0]:rows[1], cols[0]:cols[1]]