def range_invert(arrayin): max_val = np.amax(arrayin) arrayout = arrayin / max_val min_val = np.amin(arrayout) arrayout = arrayout - min_val arrayout = 1 - arrayout # inverting the range arrayout = arrayout * max_val return arrayout
def read_dicom3D(direc, i_option): # item = 0 for subdir, dirs, files in os.walk(direc): # pylint: disable = unused-variable k = 0 for file in tqdm(sorted(files)): # print('filename=', file) if os.path.splitext(file)[1] == ".dcm": dataset = pydicom.dcmread(direc + file) if k == 0: ArrayDicom = np.zeros( (dataset.Rows, dataset.Columns, 0), dtype=dataset.pixel_array.dtype, ) tmp_array = dataset.pixel_array if i_option.startswith(("y", "yeah", "yes")): max_val = np.amax(tmp_array) tmp_array = tmp_array / max_val min_val = np.amin(tmp_array) tmp_array = tmp_array - min_val tmp_array = 1 - tmp_array # inverting the range # min_val = np.amin(tmp_array) # normalizing # tmp_array = tmp_array - min_val # tmp_array = tmp_array / (np.amax(tmp_array)) tmp_array = u.norm01(tmp_array) else: # min_val = np.amin(tmp_array) # tmp_array = tmp_array - min_val # tmp_array = tmp_array / (np.amax(tmp_array)) tmp_array = u.norm01(tmp_array) # just normalize ArrayDicom = np.dstack((ArrayDicom, tmp_array)) # print("item thickness [mm]=", dataset.SliceThickness) SID = dataset.RTImageSID dx = 1 / (SID * (1 / dataset.ImagePlanePixelSpacing[0]) / 1000) dy = 1 / (SID * (1 / dataset.ImagePlanePixelSpacing[1]) / 1000) print("pixel spacing row [mm]=", dx) print("pixel spacing col [mm]=", dy) else: tmp_array = dataset.pixel_array if i_option.startswith(("y", "yeah", "yes")): max_val = np.amax(tmp_array) tmp_array = tmp_array / max_val min_val = np.amin(tmp_array) tmp_array = tmp_array - min_val tmp_array = 1 - tmp_array # inverting the range # min_val = np.amin(tmp_array) # normalizing # tmp_array = tmp_array - min_val # tmp_array = tmp_array / (np.amax(tmp_array)) tmp_array = u.norm01(tmp_array) else: # min_val = np.amin(tmp_array) # tmp_array = tmp_array - min_val # tmp_array = tmp_array / (np.amax(tmp_array)) # just normalize tmp_array = u.norm01(tmp_array) ArrayDicom = np.dstack((ArrayDicom, tmp_array)) k = k + 1 xfield, yfield, rotfield = image_analyze(ArrayDicom, i_option) multi_slice_viewer(ArrayDicom, dx, dy) if np.shape(xfield)[2] == 2: fig, peak_figs, junctions_figs = merge_view_vert(xfield, dx, dy) with PdfPages(direc + "jaws_X_report.pdf") as pdf: pdf.savefig(fig) # for i in range(0, len(peak_figs)): for _, f in enumerate(peak_figs): pdf.savefig(f) # for i in range(0, len(junctions_figs)): for _, f in enumerate(junctions_figs): pdf.savefig(f) plt.close() else: print( "X jaws data analysis not completed please verify that you have two X jaws images. For more information see manual." ) if np.shape(yfield)[2] == 4: fig, peak_figs, junctions_figs = merge_view_horz(yfield, dx, dy) # print('peak_figs********************************************************=', len(peak_figs),peak_figs) with PdfPages(direc + "jaws_Y_report.pdf") as pdf: pdf.savefig(fig) # for i in range(0, len(peak_figs)): for _, f in enumerate(peak_figs): pdf.savefig(f) for _, f in enumerate(junctions_figs): pdf.savefig(f) plt.close() else: print( "Y jaws data analysis not completed please verify that you have four Y jaws images. For more information see manual." ) if np.shape(rotfield)[2] == 4: fig, peak_figs, junctions_figs = merge_view_filtrot(rotfield, dx, dy) with PdfPages(direc + "jaws_FR_report.pdf") as pdf: pdf.savefig(fig) for _, f in enumerate(peak_figs): pdf.savefig(f) for _, f in enumerate(junctions_figs): pdf.savefig(f) plt.close() else: print( "Field rotation data analysis not completed please verify that you have four field rotation images. For more information see manual." )
def norm01(arrayin): min_val = np.amin(arrayin) # normalizing arrayout = arrayin - min_val arrayout = arrayout / (np.amax(arrayout)) # normalizing the data return arrayout
def image_analyze(volume, i_opt): xfield = [] yfield = [] rotfield = [] if i_opt.startswith(("y", "yeah", "yes")): kx = 0 ky = 0 krot = 0 for item in range(0, volume.shape[2]): stack1 = np.sum( volume[ int( np.shape(volume)[0] / 2 - np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ) : int( np.shape(volume)[0] / 2 + np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ), int( np.shape(volume)[1] / 2 - np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ) : int( np.shape(volume)[1] / 2 + np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ), item, ], axis=0, ) maxstack1 = np.amax(stack1) # stack2 = np.sum(volume[:, :, item], axis=1) stack2 = np.sum( volume[ int( np.shape(volume)[0] / 2 - np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ) : int( np.shape(volume)[0] / 2 + np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ), int( np.shape(volume)[1] / 2 - np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ) : int( np.shape(volume)[1] / 2 + np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ), item, ], axis=1, ) maxstack2 = np.amax(stack2) if maxstack2 / maxstack1 > 1.1: # It is a Y field folder if ky == 0: yfield = volume[:, :, item] yfield = yfield[:, :, np.newaxis] else: volappend = volume[:, :, item] yfield = np.append(yfield, volappend[:, :, np.newaxis], axis=2) ky = ky + 1 elif maxstack2 / maxstack1 < 0.9: # It is a X field folder if kx == 0: xfield = volume[:, :, item] xfield = xfield[:, :, np.newaxis] else: # xfield=xfield[:,:,np.newaxis] volappend = volume[:, :, item] xfield = np.append(xfield, volappend[:, :, np.newaxis], axis=2) kx = kx + 1 else: # It is a field rotation folder if krot == 0: rotfield = volume[:, :, item] rotfield = rotfield[:, :, np.newaxis] else: # rotfield = rotfield[:, :, np.newaxis] volappend = volume[:, :, item] rotfield = np.append(rotfield, volappend[:, :, np.newaxis], axis=2) krot = krot + 1 else: kx = 0 ky = 0 krot = 0 for item in range(0, volume.shape[2]): stack1 = np.sum( volume[ int( np.shape(volume)[0] / 2 - np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ) : int( np.shape(volume)[0] / 2 + np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ), int( np.shape(volume)[1] / 2 - np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ) : int( np.shape(volume)[1] / 2 + np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ), item, ], axis=0, ) maxstack1 = np.amax(stack1) # stack2 = np.sum(volume[:, :, item], axis=1) stack2 = np.sum( volume[ int( np.shape(volume)[0] / 2 - np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ) : int( np.shape(volume)[0] / 2 + np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ), int( np.shape(volume)[1] / 2 - np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ) : int( np.shape(volume)[1] / 2 + np.amin([np.shape(volume)[0], np.shape(volume)[1]]) / 2 ), item, ], axis=1, ) maxstack2 = np.amax(stack2) if maxstack2 / maxstack1 > 1.5: # It is a Y field folder if ky == 0: yfield = volume[:, :, item] yfield = yfield[:, :, np.newaxis] else: volappend = volume[:, :, item] yfield = np.append(yfield, volappend[:, :, np.newaxis], axis=2) ky = ky + 1 elif maxstack2 / maxstack1 < 0.5: # It is a X field folder if kx == 0: xfield = volume[:, :, item] xfield = xfield[:, :, np.newaxis] else: # xfield=xfield[:,:,np.newaxis] volappend = volume[:, :, item] xfield = np.append(xfield, volappend[:, :, np.newaxis], axis=2) kx = kx + 1 else: # It is a field rotation folder if krot == 0: rotfield = volume[:, :, item] rotfield = rotfield[:, :, np.newaxis] else: # rotfield = rotfield[:, :, np.newaxis] volappend = volume[:, :, item] rotfield = np.append(rotfield, volappend[:, :, np.newaxis], axis=2) krot = krot + 1 return xfield, yfield, rotfield