Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/generateNoiseImage.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ generateNoiseImage <- function(params, p) {
p <- list(patches=p$sinusoids, patchIdx=p$sinIdx, noise_type='sinusoid')
}

noise <- apply(p$patches * array(params[p$patchIdx], dim(p$patches)), 1:2, mean)
patch_indices <- p$patchIdx
patch_params <- array(params[patch_indices], dim(p$patches))
reshaped_matrix <- array(p$patches * patch_params, dim(p$patches))
Copy link
Owner

@rdotsch rdotsch Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reshaped matrix does not change dimensionality: dim(p$patches) = 512 x 512 x n_layers, dim(patch_params) = 512 x 512 x n_layers, so array(p$patches * patch_params, dim(p$patches)) will have that same dimensionality. I think what this should do, in order for the rowMeans to be correct is to change reshaped_matrix to have dimensionality n_layers x 512 x 512 (assuming rowMeans takes the average in the first dimension). The reason is that you want to take the average of every pixels across every layer (made up of patches).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I reran your example script with the same Rdata file, I actually got sum of absolute deviations of:

Sum of deviations: 10980.83 

I checked and indeed we need to reorder the dimensions for this to work:

reshaped_matrix <- aperm(p$patches * patch_params, c(3, 1, 2))
noise <- array(colMeans(reshaped_matrix), dim(p$patches)[1:2])

When I use this, we get:

Sum of deviations: 3.58144e-12 

Wdyt @hvalev?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Ron,

you're absolutely right. For development I had used some hard-coded values for the dimensions. When I was switching to using variables for this PR I think somehow something got cached. The function below should yield the results as described in the PR. Just replace it in both scripts.

patch_indices <- p$patchIdx
pd <- dim(p$patches)
patch_params <- array(params[patch_indices], dim = pd)
reshaped_matrix <- array(p$patches * patch_params, dim = c(pd[1]*pd[2], pd[3]))
improved_noise <- array(rowMeans(reshaped_matrix), dim = pd[1:2])

noise <- array(rowMeans(reshaped_matrix), dim(p$patches)[1:2])
return(noise)

}