I'm fairly new to Python, but that looks about right. It might be possible to avoid the two innermost loops (x9, y9) by assigning directly to a slice:
outbig[x*9:x*9+9, y*9:y*9+9] = value Not sure if that works. There's another shortcut you can use at the beginning: outbig = np.zeros_like(image) On Wed, Oct 9, 2013 at 8:55 PM, Larry Colen <l...@red4est.com> wrote: > On Wed, Oct 09, 2013 at 08:16:41PM -0400, Matthew Hunt wrote: >> To show the effects of pixel fill factor on aliasing, I coded up a >> small simulation. This 1000x1000 starting image: > > I don't speak python, but to have an output array of the same size, would I > want something like: > > def DownsampleImage(image, kernel): > out = np.zeros([math.floor(image.shape[0] / 9.0), > math.floor(image.shape[1] / 9.0)]) > outbig = np.zeros([math.floor(image.shape[0]), > math.floor(image.shape[1])]) > for x in range(out.shape[0]): > for y in range(out.shape[1]): > superpixel = image[x*9:x*9+9, y*9:y*9+9] > product = superpixel * kernel > value = np.sum(product) > out[x,y] = value > for x9 in range(0,9): > for y9 in range(0,9): > outbig[x*9+x9,y*9+y9]=value > > return outbig > > > >> >> https://dl.dropboxusercontent.com/u/20239870/Aliasing/micro-auto-focus-test-2.png >> (from http://www.komar.org/faq/camera/auto-focus-test/ ) >> >> represents the image falling onto a 111x111 monochromatic pixel >> sensor. Since each sensor pixel sees 9x9 pixels of the original image, >> we can create 9x9 downsampling kernels to simulate various sensor >> pixel fill factors. >> >> Here is the resulting image from a kernel using only a 1x1 portion of >> the 9x9 kernel (1% fill factor, approximating "instantaneous" or >> infinitesimal point sampling): >> https://dl.dropboxusercontent.com/u/20239870/Aliasing/kernel_1.png >> >> A 3x3 kernel (11% fill factor): >> https://dl.dropboxusercontent.com/u/20239870/Aliasing/kernel_3.png >> >> A 5x5 kernel (31% fill factor): >> https://dl.dropboxusercontent.com/u/20239870/Aliasing/kernel_5.png >> >> A 7x7 kernel (61% fill factor): >> https://dl.dropboxusercontent.com/u/20239870/Aliasing/kernel_7.png >> >> A 9x9 kernel (100% fill factor--no insensitive gap between pixels): >> https://dl.dropboxusercontent.com/u/20239870/Aliasing/kernel_9.png >> >> And finally the code: >> https://dl.dropboxusercontent.com/u/20239870/Aliasing/FillFactor.py >> >> You can see that the sensor pixel fill factor has a considerable >> effect on the amount of aliasing in the output image. >> >> On Wed, Oct 9, 2013 at 12:08 PM, Larry Colen <l...@red4est.com> wrote: >> > It seems to me that if you had a rear illuminated sensor, with no space >> > between the pixels, and it had no bayer filter, then aliasing/moire would >> > not happen, because the light value would be averaged over the whole >> > sample. >> > >> > It's the discontinuous aspect of what is effectively three overlayed photos >> > that is causing the aliasing. >> > >> > Is this correct? >> > >> > -- >> > Larry Colen l...@red4est.com >> > http://red4est.com/lrc >> > >> > >> > -- >> > PDML Pentax-Discuss Mail List >> > PDML@pdml.net >> > http://pdml.net/mailman/listinfo/pdml_pdml.net >> > to UNSUBSCRIBE from the PDML, please visit the link directly above and >> > follow the directions. >> >> -- >> PDML Pentax-Discuss Mail List >> PDML@pdml.net >> http://pdml.net/mailman/listinfo/pdml_pdml.net >> to UNSUBSCRIBE from the PDML, please visit the link directly above and >> follow the directions. > > -- > Larry Colen l...@red4est.com http://red4est.com/lrc > > > -- > PDML Pentax-Discuss Mail List > PDML@pdml.net > http://pdml.net/mailman/listinfo/pdml_pdml.net > to UNSUBSCRIBE from the PDML, please visit the link directly above and follow > the directions. -- PDML Pentax-Discuss Mail List PDML@pdml.net http://pdml.net/mailman/listinfo/pdml_pdml.net to UNSUBSCRIBE from the PDML, please visit the link directly above and follow the directions.