@@ -235,11 +235,27 @@ def plot_cross_section(
235235 zero_crossings = np .where (np .diff (np .signbit (cross_section + plot_db_drop )))[0 ]
236236 if len (zero_crossings ) >= 2 :
237237 zero_crossings -= np .argmax (cross_section )
238+ < << << << HEAD
238239 width = zero_crossings [- 1 ] - zero_crossings [0 ]
239240 ax .set_title (f"-{ plot_db_drop } dB width = { width } " )
240241 ax .axvline (x = zero_crossings [0 ], c = "k" , linestyle = "--" )
241242 ax .axvline (x = zero_crossings [- 1 ], c = "k" , linestyle = "--" )
242243 print (f"{ plot_db_drop } dB width : { width } pixels" )
244+ == == == =
245+
246+ # width = zero_crossings[-1] - zero_crossings[0]
247+ # ax.axvline(x=zero_crossings[0], c="k", linestyle="--")
248+ # ax.axvline(x=zero_crossings[-1], c="k", linestyle="--")
249+
250+ first_crossing = np .abs (zero_crossings [np .argmin (np .abs (zero_crossings ))])
251+ width = 2 * np .abs (first_crossing )
252+ ax .axvline (x = - first_crossing , c = "k" , linestyle = "--" )
253+ ax .axvline (x = + first_crossing , c = "k" , linestyle = "--" )
254+
255+ ax .set_title ("Cross-section" )
256+ ax .set_xlabel (f"-{ plot_db_drop } dB width = { width } " )
257+
258+ >> >> >> > main
243259 else :
244260 warnings .warn (
245261 "Width could not be determined. Did not detect two -{} points : {}" .format (
@@ -291,7 +307,7 @@ def plot_autocorr2d(vals, pad_mode="reflect", ax=None):
291307 return ax , autocorr
292308
293309
294- def plot_autocorr_rgb (img , width = 3 , figsize = None ):
310+ def plot_autocorr_rgb (img , width = 3 , figsize = None , plot_psf = False , psf_gamma = 2.2 ):
295311 """
296312 Plot autocorrelation of each channel of an image.
297313
@@ -307,15 +323,36 @@ def plot_autocorr_rgb(img, width=3, figsize=None):
307323 assert len (img .shape ) == 3 , "Image must be 3D"
308324 assert img .shape [2 ] == 3 , "Image must have 3 color channels"
309325
310- _ , ax_auto = plt .subplots (ncols = 3 , nrows = 2 , num = "Autocorrelations" , figsize = figsize )
311-
312- for i , c in enumerate (["r" , "g" , "b" ]):
313- _ , autocorr_c = plot_autocorr2d (img [:, :, i ], ax = ax_auto [0 ][i ])
326+ if plot_psf :
327+ _ , ax_auto = plt .subplots (ncols = 3 , nrows = 3 , num = "Autocorrelations" , figsize = figsize )
328+ else :
329+ _ , ax_auto = plt .subplots (ncols = 3 , nrows = 2 , num = "Autocorrelations" , figsize = figsize )
330+
331+ for i , c in enumerate (["Red" , "Green" , "Blue" ]):
332+ if plot_psf :
333+ plot_image (
334+ img [:, :, i ],
335+ ax = ax_auto [0 ][i ],
336+ gamma = psf_gamma ,
337+ normalize = True ,
338+ )
339+ # ax_auto[0][i].imshow(img[:, :, i], cmap="gray")
340+ ax_auto [0 ][i ].axis ("off" )
341+ ax_auto [0 ][i ].set_title (f"{ c } PSF" )
342+
343+ # plot autocorrelation
344+ _ , autocorr_c = plot_autocorr2d (img [:, :, i ], ax = ax_auto [1 if plot_psf else 0 ][i ])
345+ ax_auto [1 ][i ].set_title ("Autocorrelation" )
346+ # # -- horizontal cross-section
347+ max_idx = np .unravel_index (np .argmax (autocorr_c , axis = None ), autocorr_c .shape )
348+ idx = max_idx [0 ]
349+ # ax_auto[1][i].axhline(y=idx, c=c, linestyle="--")
314350
315351 ax , _ = plot_cross_section (
316352 autocorr_c ,
353+ idx = idx ,
317354 color = c ,
318- ax = ax_auto [1 ][i ],
355+ ax = ax_auto [2 if plot_psf else 1 ][i ],
319356 plot_db_drop = width ,
320357 )
321358 if i != 0 :
0 commit comments