|
14 | 14 | % a better estimate of the Pearson Correlation Coefficient |
15 | 15 | % (default: 20) |
16 | 16 | % ROI for a ROI, corner coordinates [xmin, xmax, ymin, ymax] pixels |
17 | | -% (default: [0, 0, 256, 256] pixels) |
| 17 | +% (default: [0, 256, 0, 256] pixels) |
18 | 18 | % |
19 | 19 | % OUTPUTS: |
20 | 20 | % pearson correlation coefficent between the Gaussian blob images of |
|
31 | 31 | SRZoom = 20; |
32 | 32 | end |
33 | 33 | if ~exist('ROI', 'var') |
34 | | - ROI = [0, 0, 256, 256]; |
| 34 | + ROI = [0, 256, 0, 256]; |
35 | 35 | end |
36 | 36 |
|
37 | 37 | SMD1a = SMD1; |
38 | 38 | SMD2a = SMD2; |
39 | | - if ROI ~= [0, 0, 256, 256] |
| 39 | + if ROI ~= [0, 256, 0, 256] |
| 40 | + % If the ROI is not the whole image ... move the ROI to (x, y) = (0, 0) |
| 41 | + % corner. This is done to perform the correlation only within the ROI, |
| 42 | + % excluding the zero pixels outside the ROI, |
40 | 43 | SMD1a.X = SMD1a.X - ROI(1); |
41 | 44 | SMD2a.X = SMD2a.X - ROI(1); |
42 | 45 | SMD1a.Y = SMD1a.Y - ROI(3); |
43 | 46 | SMD2a.Y = SMD2a.Y - ROI(3); |
| 47 | + % delta_x/y should be integer numbers of pixels. |
44 | 48 | delta_x = floor(ROI(2) - ROI(1)); |
45 | 49 | delta_y = floor(ROI(4) - ROI(3)); |
46 | 50 | SMD1a.XSize = delta_x; |
|
57 | 61 | [r, p] = corrcoef(G1, G2); |
58 | 62 | pearson = r(1, 2); |
59 | 63 | p_value = p(1, 2); |
60 | | - %fprintf('pearson = %f\n', pearson); |
61 | 64 |
|
62 | | - % Code to calculate pearson by hand. The results should be the same as |
63 | | - % using the MATLAB function corrcoef. |
64 | | - %H1 = G1(:); |
65 | | - %H2 = G2(:); |
66 | | - %pearsonA = sum((H1 - mean(H1)) .* (H2 - mean(H2))) ... |
67 | | - % ./ ((numel(H1) - 1) * std(H1) * std(H2)); |
68 | | - %fprintf('pearsonA = %f\n', pearsonA); |
| 65 | + verbose = false; |
| 66 | + if verbose |
| 67 | + fprintf('pearson = %f\n', pearson); |
| 68 | + |
| 69 | + % Code to calculate pearson by hand. The results should be the same as |
| 70 | + % using the MATLAB function corrcoef. |
| 71 | + H1 = G1(:); |
| 72 | + H2 = G2(:); |
| 73 | + pearsonA = sum((H1 - mean(H1)) .* (H2 - mean(H2))) ... |
| 74 | + ./ ((numel(H1) - 1) * std(H1) * std(H2)); |
| 75 | + fprintf('pearsonA = %f\n', pearsonA); |
| 76 | + end |
69 | 77 |
|
70 | 78 | end |
0 commit comments