Compute radial profile #74

Closed
opened 2024-05-16 00:43:35 +02:00 by Benjamin_Loison · 5 comments

The most related Wikipedia article seems to be https://en.wikipedia.org/wiki/Radial_distribution_function but still seems not related enough.

Someone asked this on Stack Overflow as the question 21242011.

Compared to original poster:

image

The answer 21242776 does not look so promising.

fft1 = np.array(Image.open('circles.jpg')

def getRadialProfile(data, center):
    y, x = np.indices((data.shape))
    r = np.sqrt((x - center[0])**2 + (y - center[1])**2)
    r = r.astype(np.uint32)

    tbin = np.bincount(r.ravel(), data.ravel())
    nr = np.bincount(r.ravel())
    radialProfile = tbin / nr
    return radialProfile

#radialProfile = getRadialProfile(np.log10(abs(fft1)), np.array(fft1.shape) / 2)
radialProfile = getRadialProfile(fft1, np.array(fft1.shape) / 2)
plt.plot(radialProfile)
plt.show()

circles.jpg being above image, maybe it is because the original poster works with raw data, other than the image itself.

answer_21242776

Related to #70.

The most related Wikipedia article seems to be https://en.wikipedia.org/wiki/Radial_distribution_function but still seems not related enough. Someone asked this on Stack Overflow as [the question 21242011](https://stackoverflow.com/q/21242011). Compared to original poster: ![image](/attachments/51442735-9712-48b8-b28b-995f84efdffe) [The answer 21242776](https://stackoverflow.com/a/21242776) does not look so promising. ```python fft1 = np.array(Image.open('circles.jpg') def getRadialProfile(data, center): y, x = np.indices((data.shape)) r = np.sqrt((x - center[0])**2 + (y - center[1])**2) r = r.astype(np.uint32) tbin = np.bincount(r.ravel(), data.ravel()) nr = np.bincount(r.ravel()) radialProfile = tbin / nr return radialProfile #radialProfile = getRadialProfile(np.log10(abs(fft1)), np.array(fft1.shape) / 2) radialProfile = getRadialProfile(fft1, np.array(fft1.shape) / 2) plt.plot(radialProfile) plt.show() ``` `circles.jpg` being above image, maybe it is because the original poster works with raw data, other than the image itself. ![answer_21242776](/attachments/43c31304-b90e-48c8-b912-c01c23860544) Related to #70.
Benjamin_Loison added the
enhancement
medium priority
quick
labels 2024-05-16 00:43:35 +02:00
Author
Owner

In fact if I use the center he specified (that is (509, 546)) that is not the center of the image (that is (552.5, 528)), then I get:

answer_21242776_correct_center

The different x axis scale remains unclear.

The peaks I found are at 270, 314, 450 and 517 which match quite perfecly what I measure with GIMP.

On my FFT the center of the image is also the center of the pattern but I still face a quite not satisfying result:

fft_radial_profile

While we expect peaks at about 40 and 83. These peaks are not clearly visible.

In fact if I use the center he specified (that is `(509, 546)`) that is not the center of the image (that is `(552.5, 528)`), then I get: ![answer_21242776_correct_center](/attachments/d3876117-27ef-42b1-8a18-f9d740d0a0d4) The different x axis scale remains unclear. The peaks I found are at 270, 314, 450 and 517 which match quite perfecly what I measure with GIMP. On my FFT the center of the image is also the center of the pattern but I still face a quite not satisfying result: ![fft_radial_profile](/attachments/5dde77e6-19e4-4010-8aaa-9fb8e3a9f41a) While we expect peaks at about 40 and 83. These peaks are not clearly visible.
Author
Owner

Translated with LibreTranslate from Google Doc Minutes:

In fact, what explains the difficulties in obtaining an interesting radial profile in the Fourier domain for the PRNU estimate is due to the fact that it is not circles but ellipses that are observed in this Fourier domain, this is particularly visible when one is interested in the profile of the two axes:

image

image

So we should expect more extensive ellipses on the axis of the ordered ones, but this is not obvious, an idea to determine whether they are circles or ellipses in the field of images? For trying by hand we talk about precision a few pixels and ??

Translated with LibreTranslate from Google Doc Minutes: > In fact, what explains the difficulties in obtaining an interesting radial profile in the Fourier domain for the PRNU estimate is due to the fact that it is not circles but ellipses that are observed in this Fourier domain, this is particularly visible when one is interested in the profile of the two axes: ![image](/attachments/11eccfc8-dba7-4a4a-93df-d542aee9132d) ![image](/attachments/60586edd-173c-4dab-8405-210ad4173711) > So we should expect more extensive ellipses on the axis of the ordered ones, but this is not obvious, an idea to determine whether they are circles or ellipses in the field of images? For trying by hand we talk about precision a few pixels and ??
132 KiB
2.7 MiB
Author
Owner
#print(f'{image.shape=}')
halfWidthPad = (image.shape[1] - image.shape[0]) // 2
image = image[:,halfWidthPad:-halfWidthPad]
#print(image.shape)
```python #print(f'{image.shape=}') halfWidthPad = (image.shape[1] - image.shape[0]) // 2 image = image[:,halfWidthPad:-halfWidthPad] #print(image.shape) ```
Author
Owner

Do not use analyze_fft_ellipses.py, as it considers axes and here they are inpainted.

largest_crop_fft largest_crop_radial_profile

So we correctly obtain circles.

Do not use `analyze_fft_ellipses.py`, as it considers axes and here they are inpainted. <img width="2897" alt="largest_crop_fft" src="/attachments/2d86540d-49fb-4ab2-9d9e-9802de8edd30"> <img width="812" alt="largest_crop_radial_profile" src="/attachments/1165311f-cdd0-4640-bda2-47424fcee35d"> So we correctly obtain circles.
Author
Owner
plt.xlabel('Distance to the circle center')
plt.ylabel('Average of the Fourier domain pixels at this distance from the circle center')

y-axis label looks too long:

Figure_1

```python plt.xlabel('Distance to the circle center') plt.ylabel('Average of the Fourier domain pixels at this distance from the circle center') ``` y-axis label looks too long: ![Figure_1](/attachments/9eab0da7-3c1a-41d9-8e54-e84bf6e44160)
Sign in to join this conversation.
No description provided.