"Why does first calling the function radon and then iradon on the result produce extra rows and columns?"
The functions radon and iradon are not exact inverses in the sense of “64×64 in -> 64×64 out”. The size change comes from geometry: how long the projections are in radon, and how iradon chooses the reconstruction size N from that projection length. Lets consider your example:
size(P)
ans =
64 64
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
size(R)
ans =
95 180
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Q0 = iradon(R,theta)
Q0 =
0.0028 0.0019 -0.0069 0.0079 -0.0021 -0.0029 0.0030 0.0033 -0.0045 -0.0010 0.0007 -0.0043 0.0025 0.0022 -0.0052 0.0033 0.0020 -0.0030 0.0010 -0.0015 -0.0006 0.0010 -0.0072 0.0077 -0.0015 -0.0032 0.0078 -0.0042 0.0030 0.0038
-0.0001 0.0061 0.0006 -0.0073 0.0069 -0.0030 -0.0080 0.0122 -0.0010 -0.0052 0.0058 -0.0051 -0.0052 0.0085 -0.0056 -0.0061 0.0072 -0.0059 -0.0023 0.0068 0.0006 -0.0057 -0.0020 0.0019 -0.0013 0.0006 0.0028 -0.0027 0.0009 0.0015
-0.0021 0.0004 0.0013 -0.0052 -0.0002 0.0035 -0.0019 -0.0050 0.0091 -0.0066 0.0028 0.0067 -0.0081 0.0071 0.0014 -0.0096 0.0087 0.0048 -0.0066 0.0002 0.0081 -0.0097 0.0063 0.0044 -0.0068 0.0127 -0.0084 0.0070 0.0097 -0.0026
-0.0027 -0.0039 0.0016 0.0027 -0.0073 0.0042 0.0040 -0.0109 0.0027 -0.0025 -0.0044 0.0059 -0.0065 -0.0004 0.0043 -0.0056 -0.0001 0.0006 0.0035 -0.0050 0.0046 -0.0040 0.0052 0.0039 -0.0133 0.0091 -0.0202 -0.0070 0.0277 0.1329
0.0007 -0.0002 -0.0019 0.0025 0.0029 -0.0035 0.0019 0.0051 -0.0055 0.0037 -0.0069 -0.0026 -0.0011 0.0020 -0.0049 -0.0015 0.0048 -0.0095 -0.0005 -0.0001 -0.0084 -0.0046 -0.0057 -0.0067 0.0040 0.0535 0.1792 0.2167 0.3318 0.6804
0.0011 0.0044 -0.0041 -0.0052 0.0078 -0.0037 -0.0023 0.0075 0.0016 -0.0006 0.0040 -0.0012 -0.0045 0.0089 -0.0076 -0.0054 0.0130 -0.0028 -0.0036 0.0121 0.0006 0.0147 0.0166 0.0308 0.1485 0.2977 0.6682 0.8036 0.7994 0.8656
-0.0068 0.0007 0.0053 -0.0057 -0.0034 0.0133 -0.0079 -0.0006 0.0046 -0.0035 0.0015 0.0112 -0.0026 0.0099 0.0092 -0.0080 0.0073 0.0030 -0.0012 0.0093 -0.0093 -0.0164 0.0431 0.2867 0.7029 0.8029 0.8210 0.8437 0.7391 0.4639
0.0043 -0.0062 0.0052 0.0079 -0.0080 0.0019 0.0076 -0.0070 0.0039 -0.0006 -0.0175 0.0047 -0.0062 -0.0051 -0.0066 0.0007 0.0032 -0.0126 -0.0074 -0.0145 0.0504 0.1617 0.3069 0.6705 0.8433 0.7580 0.4691 0.3506 0.3280 0.2121
0.0053 -0.0044 -0.0072 0.0057 -0.0044 -0.0084 0.0032 -0.0010 -0.0035 0.0061 -0.0055 0.0006 -0.0074 0.0106 -0.0061 -0.0024 0.0088 -0.0129 0.0280 0.0364 0.2742 0.7028 0.8291 0.7358 0.4429 0.3144 0.2439 0.1840 0.2208 0.1943
-0.0001 0.0042 -0.0062 -0.0052 0.0075 -0.0026 -0.0038 0.0002 -0.0010 0.0052 0.0053 0.0116 -0.0016 0.0072 -0.0005 -0.0104 0.0287 -0.0149 0.0205 0.2983 0.7099 0.9159 0.7638 0.4485 0.2350 0.1960 0.1931 0.2018 0.2009 0.1917
-0.0056 0.0041 0.0075 -0.0025 0.0021 0.0091 0.0040 -0.0004 0.0017 0.0003 -0.0163 -0.0045 -0.0137 -0.0072 0.0103 0.0022 -0.0193 0.0556 0.3085 0.6863 0.9535 0.7769 0.4189 0.2152 0.1888 0.2129 0.1946 0.2120 0.1801 0.2214
0.0028 -0.0015 0.0002 0.0085 -0.0009 -0.0056 0.0031 -0.0040 -0.0057 0.0098 -0.0066 0.0075 0.0153 0.0151 -0.0307 0.0065 0.0308 0.1190 0.6877 0.9176 0.7892 0.4243 0.2402 0.2138 0.2049 0.1985 0.1948 0.2025 0.2130 0.1924
0.0031 0.0033 -0.0079 -0.0056 0.0020 -0.0097 -0.0104 0.0022 -0.0065 0.0016 -0.0003 0.0029 -0.0159 -0.0039 0.0259 -0.0109 0.0377 0.3352 0.8328 0.7623 0.4307 0.2176 0.1995 0.1775 0.2134 0.1835 0.2155 0.1874 0.1964 0.1981
-0.0081 -0.0018 0.0071 -0.0066 0.0045 0.0109 0.0024 0.0120 0.0062 0.0014 -0.0095 -0.0080 0.0131 -0.0006 -0.0300 0.0516 0.2793 0.6823 0.7274 0.4023 0.2595 0.1819 0.2247 0.1938 0.2037 0.2015 0.1934 0.1996 0.2048 0.2078
0.0036 -0.0049 0.0136 0.0090 -0.0098 0.0047 -0.0053 -0.0046 -0.0025 0.0046 0.0043 -0.0023 0.0132 -0.0109 0.0229 0.1612 0.6769 0.7365 0.4501 0.2282 0.2002 0.2022 0.1996 0.1944 0.1998 0.2083 0.2062 0.2057 0.1959 0.2151
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
size(Q0)
ans =
66 66
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
So the key numbers are:
- original image: 64×64
- projection length: len = size(R,1) = 95
- reconstructed image: N×N with N = 66
Inside iradon
The value of N is defined when the inputs are parsed:
[p,theta,filter,d,interp,N] = images.internal.iradon.parseInputs(args{:});
N is the output image size. When you call
without specifying N, parseInputs picks a default value of N based on size(p,1) (the number of rows in R). So iradon does notknow that your original image was 64×64; it only sees a sinogram of length 95 and chooses an N that fits that. Later inside iradon:
len = size(p,1);
ctrIdx = ceil(len/2);
imgDiag = 2*ceil(N/sqrt(2))+1;
if size(p,1) < imgDiag
rz = imgDiag - size(p,1);
p = [zeros(ceil(rz/2),size(p,2)); p; zeros(floor(rz/2),size(p,2))];
ctrIdx = ctrIdx+ceil(rz/2);
end
Interpretation:
- len = size(p,1) is the length of each projection (95 in your case).
- imgDiag = 2*ceil(N/sqrt(2)) + 1 is the number of samples needed along a projection to cover the longest line through an N×N image (the image “diagonal” in pixel units).
- If the projections are too short for that N, they get zero-padded to length imgDiag.
In your case, no extra padding is added here, because len already matches imgDiag for N = 66:
len = 95;
imgDiag = 2*ceil(66/sqrt(2)) + 1 = 2*47 + 1 = 95;
size(p,1) < imgDiag % false, so no padding
So the “extra 2 pixels” in each direction do not come from this padding step – they come from how N was chosen earlier.
Why N=66 and not 64?
The geometric requirement is:
2*ceil(N/sqrt(2)) + 1 <= len
so that the projections are long enough to cover the diagonal of an N×N image.
Given len = 95, the largest N that satisfies this inequality is N = 66:
- For N = 66:imgDiag = 2*ceil(66/sqrt(2)) + 1 = 2*47 + 1 = 95 <= 95 % just right
- For N = 67:imgDiag = 2*ceil(67/sqrt(2)) + 1 = 2*48 + 1 = 97 > 95 % too large
So, from the sinogram length 95 alone, the “maximal” consistent reconstruction size is 66×66. Since you didn’t tell iradonotherwise, parseInputs chooses that size. Notice that N = 64 would also satisfy the inequality:
2*ceil(64/sqrt(2)) + 1 = 2*46 + 1 = 93 <= 95
but iradon doesn’t know you started from 64×64; it just sees that it can go up to 66×66 with the available projection length, so it does. At this point you have:
- radon: created projections long enough to cover your 64×64 image (and a bit more), resulting in 95 samples per projection.
- iradon: looked at those 95 samples and chose the largest N consistent with them, which is N = 66.
That’s why a 64×64 image becomes 66×66 after radon → iradon with default parameters.
What about radon giving 95 rows?
For completeness: radon chooses the number of samples per projection to cover the full image at all angles (roughly a diagonal-based formula plus some discrete/rounding margin). For a 64×64 image, that works out to 95 samples, which is exactly what iradon then interprets as sufficient for a 66×66 reconstruction.
So the chain is:
64×64 image
↓ (radon chooses length 95 to cover geometry)
95×180 sinogram
↓ (iradon chooses largest N such that diagonal fits in length 95)
66×66 reconstruction
How to get back to 64×64
If you want iradon to give you a 64×64 image, you must tell it explicitly:
Q1 = iradon(R, theta, 64)
Q1 =
0.0061 0.0006 -0.0073 0.0069 -0.0030 -0.0080 0.0122 -0.0010 -0.0052 0.0058 -0.0051 -0.0052 0.0085 -0.0056 -0.0061 0.0072 -0.0059 -0.0023 0.0068 0.0006 -0.0057 -0.0020 0.0019 -0.0013 0.0006 0.0028 -0.0027 0.0009 0.0015 0.0003
0.0004 0.0013 -0.0052 -0.0002 0.0035 -0.0019 -0.0050 0.0091 -0.0066 0.0028 0.0067 -0.0081 0.0071 0.0014 -0.0096 0.0087 0.0048 -0.0066 0.0002 0.0081 -0.0097 0.0063 0.0044 -0.0068 0.0127 -0.0084 0.0070 0.0097 -0.0026 0.0154
-0.0039 0.0016 0.0027 -0.0073 0.0042 0.0040 -0.0109 0.0027 -0.0025 -0.0044 0.0059 -0.0065 -0.0004 0.0043 -0.0056 -0.0001 0.0006 0.0035 -0.0050 0.0046 -0.0040 0.0052 0.0039 -0.0133 0.0091 -0.0202 -0.0070 0.0277 0.1329 0.1853
-0.0002 -0.0019 0.0025 0.0029 -0.0035 0.0019 0.0051 -0.0055 0.0037 -0.0069 -0.0026 -0.0011 0.0020 -0.0049 -0.0015 0.0048 -0.0095 -0.0005 -0.0001 -0.0084 -0.0046 -0.0057 -0.0067 0.0040 0.0535 0.1792 0.2167 0.3318 0.6804 0.7953
0.0044 -0.0041 -0.0052 0.0078 -0.0037 -0.0023 0.0075 0.0016 -0.0006 0.0040 -0.0012 -0.0045 0.0089 -0.0076 -0.0054 0.0130 -0.0028 -0.0036 0.0121 0.0006 0.0147 0.0166 0.0308 0.1485 0.2977 0.6682 0.8036 0.7994 0.8656 0.8609
0.0007 0.0053 -0.0057 -0.0034 0.0133 -0.0079 -0.0006 0.0046 -0.0035 0.0015 0.0112 -0.0026 0.0099 0.0092 -0.0080 0.0073 0.0030 -0.0012 0.0093 -0.0093 -0.0164 0.0431 0.2867 0.7029 0.8029 0.8210 0.8437 0.7391 0.4639 0.3386
-0.0062 0.0052 0.0079 -0.0080 0.0019 0.0076 -0.0070 0.0039 -0.0006 -0.0175 0.0047 -0.0062 -0.0051 -0.0066 0.0007 0.0032 -0.0126 -0.0074 -0.0145 0.0504 0.1617 0.3069 0.6705 0.8433 0.7580 0.4691 0.3506 0.3280 0.2121 0.2007
-0.0044 -0.0072 0.0057 -0.0044 -0.0084 0.0032 -0.0010 -0.0035 0.0061 -0.0055 0.0006 -0.0074 0.0106 -0.0061 -0.0024 0.0088 -0.0129 0.0280 0.0364 0.2742 0.7028 0.8291 0.7358 0.4429 0.3144 0.2439 0.1840 0.2208 0.1943 0.2116
0.0042 -0.0062 -0.0052 0.0075 -0.0026 -0.0038 0.0002 -0.0010 0.0052 0.0053 0.0116 -0.0016 0.0072 -0.0005 -0.0104 0.0287 -0.0149 0.0205 0.2983 0.7099 0.9159 0.7638 0.4485 0.2350 0.1960 0.1931 0.2018 0.2009 0.1917 0.1956
0.0041 0.0075 -0.0025 0.0021 0.0091 0.0040 -0.0004 0.0017 0.0003 -0.0163 -0.0045 -0.0137 -0.0072 0.0103 0.0022 -0.0193 0.0556 0.3085 0.6863 0.9535 0.7769 0.4189 0.2152 0.1888 0.2129 0.1946 0.2120 0.1801 0.2214 0.2032
-0.0015 0.0002 0.0085 -0.0009 -0.0056 0.0031 -0.0040 -0.0057 0.0098 -0.0066 0.0075 0.0153 0.0151 -0.0307 0.0065 0.0308 0.1190 0.6877 0.9176 0.7892 0.4243 0.2402 0.2138 0.2049 0.1985 0.1948 0.2025 0.2130 0.1924 0.1893
0.0033 -0.0079 -0.0056 0.0020 -0.0097 -0.0104 0.0022 -0.0065 0.0016 -0.0003 0.0029 -0.0159 -0.0039 0.0259 -0.0109 0.0377 0.3352 0.8328 0.7623 0.4307 0.2176 0.1995 0.1775 0.2134 0.1835 0.2155 0.1874 0.1964 0.1981 0.2123
-0.0018 0.0071 -0.0066 0.0045 0.0109 0.0024 0.0120 0.0062 0.0014 -0.0095 -0.0080 0.0131 -0.0006 -0.0300 0.0516 0.2793 0.6823 0.7274 0.4023 0.2595 0.1819 0.2247 0.1938 0.2037 0.2015 0.1934 0.1996 0.2048 0.2078 0.1843
-0.0049 0.0136 0.0090 -0.0098 0.0047 -0.0053 -0.0046 -0.0025 0.0046 0.0043 -0.0023 0.0132 -0.0109 0.0229 0.1612 0.6769 0.7365 0.4501 0.2282 0.2002 0.2022 0.1996 0.1944 0.1998 0.2083 0.2062 0.2057 0.1959 0.2151 0.2411
-0.0024 -0.0152 0.0029 -0.0020 -0.0067 0.0047 -0.0011 -0.0012 -0.0120 0.0095 -0.0058 -0.0090 0.0021 0.0205 0.3471 0.6898 0.4496 0.2217 0.1930 0.1900 0.2086 0.1893 0.2128 0.1955 0.2008 0.1916 0.1960 0.2313 0.2726 0.2758
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
size(Q1)
ans =
64 64
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Q2 = iradon(R, theta, 'linear', 'Ram-Lak', 1.0, 64)
Q2 =
0.0061 0.0006 -0.0073 0.0069 -0.0030 -0.0080 0.0122 -0.0010 -0.0052 0.0058 -0.0051 -0.0052 0.0085 -0.0056 -0.0061 0.0072 -0.0059 -0.0023 0.0068 0.0006 -0.0057 -0.0020 0.0019 -0.0013 0.0006 0.0028 -0.0027 0.0009 0.0015 0.0003
0.0004 0.0013 -0.0052 -0.0002 0.0035 -0.0019 -0.0050 0.0091 -0.0066 0.0028 0.0067 -0.0081 0.0071 0.0014 -0.0096 0.0087 0.0048 -0.0066 0.0002 0.0081 -0.0097 0.0063 0.0044 -0.0068 0.0127 -0.0084 0.0070 0.0097 -0.0026 0.0154
-0.0039 0.0016 0.0027 -0.0073 0.0042 0.0040 -0.0109 0.0027 -0.0025 -0.0044 0.0059 -0.0065 -0.0004 0.0043 -0.0056 -0.0001 0.0006 0.0035 -0.0050 0.0046 -0.0040 0.0052 0.0039 -0.0133 0.0091 -0.0202 -0.0070 0.0277 0.1329 0.1853
-0.0002 -0.0019 0.0025 0.0029 -0.0035 0.0019 0.0051 -0.0055 0.0037 -0.0069 -0.0026 -0.0011 0.0020 -0.0049 -0.0015 0.0048 -0.0095 -0.0005 -0.0001 -0.0084 -0.0046 -0.0057 -0.0067 0.0040 0.0535 0.1792 0.2167 0.3318 0.6804 0.7953
0.0044 -0.0041 -0.0052 0.0078 -0.0037 -0.0023 0.0075 0.0016 -0.0006 0.0040 -0.0012 -0.0045 0.0089 -0.0076 -0.0054 0.0130 -0.0028 -0.0036 0.0121 0.0006 0.0147 0.0166 0.0308 0.1485 0.2977 0.6682 0.8036 0.7994 0.8656 0.8609
0.0007 0.0053 -0.0057 -0.0034 0.0133 -0.0079 -0.0006 0.0046 -0.0035 0.0015 0.0112 -0.0026 0.0099 0.0092 -0.0080 0.0073 0.0030 -0.0012 0.0093 -0.0093 -0.0164 0.0431 0.2867 0.7029 0.8029 0.8210 0.8437 0.7391 0.4639 0.3386
-0.0062 0.0052 0.0079 -0.0080 0.0019 0.0076 -0.0070 0.0039 -0.0006 -0.0175 0.0047 -0.0062 -0.0051 -0.0066 0.0007 0.0032 -0.0126 -0.0074 -0.0145 0.0504 0.1617 0.3069 0.6705 0.8433 0.7580 0.4691 0.3506 0.3280 0.2121 0.2007
-0.0044 -0.0072 0.0057 -0.0044 -0.0084 0.0032 -0.0010 -0.0035 0.0061 -0.0055 0.0006 -0.0074 0.0106 -0.0061 -0.0024 0.0088 -0.0129 0.0280 0.0364 0.2742 0.7028 0.8291 0.7358 0.4429 0.3144 0.2439 0.1840 0.2208 0.1943 0.2116
0.0042 -0.0062 -0.0052 0.0075 -0.0026 -0.0038 0.0002 -0.0010 0.0052 0.0053 0.0116 -0.0016 0.0072 -0.0005 -0.0104 0.0287 -0.0149 0.0205 0.2983 0.7099 0.9159 0.7638 0.4485 0.2350 0.1960 0.1931 0.2018 0.2009 0.1917 0.1956
0.0041 0.0075 -0.0025 0.0021 0.0091 0.0040 -0.0004 0.0017 0.0003 -0.0163 -0.0045 -0.0137 -0.0072 0.0103 0.0022 -0.0193 0.0556 0.3085 0.6863 0.9535 0.7769 0.4189 0.2152 0.1888 0.2129 0.1946 0.2120 0.1801 0.2214 0.2032
-0.0015 0.0002 0.0085 -0.0009 -0.0056 0.0031 -0.0040 -0.0057 0.0098 -0.0066 0.0075 0.0153 0.0151 -0.0307 0.0065 0.0308 0.1190 0.6877 0.9176 0.7892 0.4243 0.2402 0.2138 0.2049 0.1985 0.1948 0.2025 0.2130 0.1924 0.1893
0.0033 -0.0079 -0.0056 0.0020 -0.0097 -0.0104 0.0022 -0.0065 0.0016 -0.0003 0.0029 -0.0159 -0.0039 0.0259 -0.0109 0.0377 0.3352 0.8328 0.7623 0.4307 0.2176 0.1995 0.1775 0.2134 0.1835 0.2155 0.1874 0.1964 0.1981 0.2123
-0.0018 0.0071 -0.0066 0.0045 0.0109 0.0024 0.0120 0.0062 0.0014 -0.0095 -0.0080 0.0131 -0.0006 -0.0300 0.0516 0.2793 0.6823 0.7274 0.4023 0.2595 0.1819 0.2247 0.1938 0.2037 0.2015 0.1934 0.1996 0.2048 0.2078 0.1843
-0.0049 0.0136 0.0090 -0.0098 0.0047 -0.0053 -0.0046 -0.0025 0.0046 0.0043 -0.0023 0.0132 -0.0109 0.0229 0.1612 0.6769 0.7365 0.4501 0.2282 0.2002 0.2022 0.1996 0.1944 0.1998 0.2083 0.2062 0.2057 0.1959 0.2151 0.2411
-0.0024 -0.0152 0.0029 -0.0020 -0.0067 0.0047 -0.0011 -0.0012 -0.0120 0.0095 -0.0058 -0.0090 0.0021 0.0205 0.3471 0.6898 0.4496 0.2217 0.1930 0.1900 0.2086 0.1893 0.2128 0.1955 0.2008 0.1916 0.1960 0.2313 0.2726 0.2758
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
size(Q2)
ans =
64 64
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Now N is fixed at 64, and the output will be 64×64.
Summary
The extra rows and columns are not a bug; they are a result of iradon’s default choice of reconstruction size N, which is derived from the projection length size(R,1), not from the original image size. For your len = 95, the largest consistent square is 66×66, so that’s what you get unless you override N.