2
$\begingroup$

Not sure if I should post this here or on Stack Overflow

I have a .csv file from MTF Mapper with 2 columns from SFR measurement - frequency and contrast:

frequency,contrast
0.0000,1.00000000
0.0156,0.99226302
0.0312,0.97449332
0.0469,0.95280915
0.0625,0.92804134
0.0781,0.90084362
0.0938,0.87229812
0.1094,0.84183842
0.1250,0.80974555
0.1406,0.77668953
0.1562,0.74314117
0.1719,0.70965093
0.1875,0.67639011
0.2031,0.64366621
0.2188,0.61178929
0.2344,0.58068842
0.2500,0.55053216
0.2656,0.52145660
0.2812,0.49323431
0.2969,0.46594858
0.3125,0.43954268
0.3281,0.41392314
0.3438,0.38908511
0.3594,0.36497608
0.3750,0.34156391
0.3906,0.31885484
0.4062,0.29684502
0.4219,0.27555731
0.4375,0.25502467
0.4531,0.23528084
0.4688,0.21636434
0.4844,0.19830902
0.5000,0.18114094
0.5156,0.16488047
0.5312,0.14953880
0.5469,0.13512121
0.5625,0.12162779
0.5781,0.10905402
0.5938,0.09739193
0.6094,0.08663070
0.6250,0.07675606
0.6406,0.06774881
0.6562,0.05958339
0.6719,0.05222636
0.6875,0.04563597
0.7031,0.03976243
0.7188,0.03454988
0.7344,0.02993968
0.7500,0.02587371
0.7656,0.02229687
0.7812,0.01915882
0.7969,0.01641583
0.8125,0.01403113
0.8281,0.01197377
0.8438,0.01021644
0.8594,0.00873312
0.8750,0.00749712
0.8906,0.00647967
0.9062,0.00564998
0.9219,0.00497617
0.9375,0.00442757
0.9531,0.00397742
0.9688,0.00360473
0.9844,0.00329490
1.0000,0.00303968
1.0156,0.00283604
1.0312,0.00268339
1.0469,0.00258079
1.0625,0.00252440
1.0781,0.00250612
1.0938,0.00251330
1.1094,0.00252985
1.1250,0.00253848
1.1406,0.00252387
1.1562,0.00247637
1.1719,0.00239507
1.1875,0.00228909
1.2031,0.00217677
1.2188,0.00208272
1.2344,0.00203381
1.2500,0.00205490
1.2656,0.00216521
1.2812,0.00237530
1.2969,0.00268560
1.3125,0.00308659
1.3281,0.00356041
1.3438,0.00408355
1.3594,0.00463053
1.3750,0.00517768
1.3906,0.00570586
1.4062,0.00620173
1.4219,0.00665721
1.4375,0.00706794
1.4531,0.00743180
1.4688,0.00774724
1.4844,0.00801171
1.5000,0.00822031
1.5156,0.00836538
1.5312,0.00843690
1.5469,0.00842374
1.5625,0.00831558
1.5781,0.00810513
1.5938,0.00779004
1.6094,0.00737425
1.6250,0.00686854
1.6406,0.00629097
1.6562,0.00566513
1.6719,0.00502094
1.6875,0.00439237
1.7031,0.00381375
1.7188,0.00331616
1.7344,0.00292386
1.7500,0.00263753
1.7656,0.00248918
1.7812,0.00246951
1.7969,0.00255373
1.8125,0.00271149
1.8281,0.00290649
1.8438,0.00310093
1.8594,0.00350206
1.8750,0.00356246
1.8906,0.00350937
1.9062,0.00339383
1.9219,0.00320148
1.9375,0.00295960
1.9531,0.00270159
1.9688,0.00252717
1.9844,0.00244180

I would like to generate a PSF image from that data (same size as the original data, no gamma correction)

Currently I use the code from this question, and it sort of works(?), but the output image is not perfect (central pixel is actually 2x3 pixels, not sure if brightness is accurate as well). There is also this question which seems to be what I need but I can't get it to work.

Is there a better code or way to do what I'm doing?

$\endgroup$
1
  • $\begingroup$ Welcome to SE.SP! Can you say why "I can't get it to work" for the second link? This question is close to off-topic here, because code requests (by themselves) are off-topic. However, please add the extra information and that might push it more to being on-topic. $\endgroup$
    – Peter K.
    Nov 30, 2021 at 18:33

1 Answer 1

1
$\begingroup$

I just took the code from your second link and did:

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d

def centeredDistanceMatrix(n):
    # make sure n is odd
    x,y = np.meshgrid(range(n),range(n))
    return np.sqrt((x-(n/2)+1)**2+(y-(n/2)+1)**2)

def function(d):
    return np.log(d) # or any funciton you might have

def arbitraryfunction(d,y,n):
    x = np.arange(n) 
    f = interp1d(x, y)
    return f(d.flat).reshape(d.shape)

n = 128
d = centeredDistanceMatrix(n)
y = data[:,1]
f = arbitraryfunction(d,y,n)
plt.plot(np.arange(n),arbitraryfunction(np.arange(n),y,n))
plt.show()
plt.imshow(f.T,origin='lower',interpolation='nearest')
plt.show()

where I wrapped your data in data = np.array([[0.0000,1.00000000], ...]).

That code generates the two images below. As I said in the comments, please let us know what is wrong with the second approach. If I look around the center, I get what I believe is appropriate:

f.T[62:65,62:65] 
array([[0.98490257, 0.99226302, 0.98490257],
        [0.99226302, 1.        , 0.99226302],
        [0.98490257, 0.99226302, 0.98490257]])

1D plot of the values

Radially symmetric image

Full Jupyter notebook here.

$\endgroup$
2
  • $\begingroup$ Thank you very much, this code now works for me. The only problem I see is that it doesn't show anything beyond frequency 1, what is the best way to fix that? $\endgroup$
    – user60345
    Dec 1, 2021 at 7:56
  • $\begingroup$ Edit: looked at your ipynb, guess I will use the second code which doesn't have this problem, thanks again $\endgroup$
    – user60345
    Dec 1, 2021 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.