Hello,
I would like to know if there is a 2D circular convolution available in IJ (or in a plugin). Thanks, Pol -- Pol Kennel |
Hi Pol,
Process>FFT>FD Math (like all FFT functions, except the filters) has periodic boundary conditions, so it is circular convolution. The images have to be square, with both having the same size, and the size must be a power of 2. Michael ________________________________________________________________ On 14 Oct 2011, at 17:42, Pol kennel wrote: > Hello, > > I would like to know if there is a 2D circular convolution > available in IJ > (or in a plugin). > > Thanks, > Pol > > -- > Pol Kennel |
Hi Michael,
Thank you for your reply, I didn't noticed this ! So, in case of non square matrix with a size that is not a power of 2, should I pad it with zero values ? How to get the convolved matrix with the original size after that ? Cheers, Pol 2011/10/14 Michael Schmid <[hidden email]> > Hi Pol, > > Process>FFT>FD Math (like all FFT functions, except the filters) has > periodic boundary conditions, so it is circular convolution. The images have > to be square, with both having the same size, and the size must be a power > of 2. > > Michael > ______________________________**______________________________**____ > > > On 14 Oct 2011, at 17:42, Pol kennel wrote: > > Hello, >> >> I would like to know if there is a 2D circular convolution available in IJ >> (or in a plugin). >> >> Thanks, >> Pol >> >> -- >> Pol Kennel >> > -- Pol Kennel |
Hi Pol,
if you want to take advantage of the periodic boundary conditions, don't pad it but rather enlarge it to a size that is a power of 2. If one of your images is smaller than the other one at the desired scale (by an integer factor, it won't work otherwise), you have to replicate the smaller one to get the same size. One possibility for replication is adding the image repeatedly to a stack and then using 'Make Montage' with a scale factor of 1 and no border or labels. Michael ________________________________________________________________ On 14 Oct 2011, at 19:01, Pol kennel wrote: > Hi Michael, > > Thank you for your reply, I didn't noticed this ! So, in case of > non square > matrix with a size that is not a power of 2, should I pad it with zero > values ? How to get the convolved matrix with the original size > after that ? > > Cheers, > Pol > > 2011/10/14 Michael Schmid <[hidden email]> > >> Hi Pol, >> >> Process>FFT>FD Math (like all FFT functions, except the filters) has >> periodic boundary conditions, so it is circular convolution. The >> images have >> to be square, with both having the same size, and the size must be >> a power >> of 2. >> >> Michael >> ______________________________**______________________________**____ >> >> >> On 14 Oct 2011, at 17:42, Pol kennel wrote: >> >> Hello, >>> >>> I would like to know if there is a 2D circular convolution >>> available in IJ >>> (or in a plugin). >>> >>> Thanks, >>> Pol >>> >>> -- >>> Pol Kennel >>> >> > > > -- > Pol Kennel |
Hi Michael,
Thank you for you attention. The thing is I have to convolve a 4x12 features matrix by a 4x12 mask, not a image, but anyway. So, using the fft method, I necessarily have to interpolate my matrices to 16 by 16 ? How to come back to a 4x12 matrix after that ? I would like to implement the non dft method, but I am not sure of how it works in 2D (I think it s ok in 1D) and don't find any explications on the web. Thank you if you can help me... Best regards, Pol 2011/10/14 Michael Schmid <[hidden email]> > Hi Pol, > > if you want to take advantage of the periodic boundary conditions, don't > pad it but rather enlarge it to a size that is a power of 2. > > If one of your images is smaller than the other one at the desired scale > (by an integer factor, it won't work otherwise), you have to replicate the > smaller one to get the same size. > One possibility for replication is adding the image repeatedly to a stack > and then using 'Make Montage' with a scale factor of 1 and no border or > labels. > > Michael > ______________________________**______________________________**____ > > > On 14 Oct 2011, at 19:01, Pol kennel wrote: > > Hi Michael, >> >> Thank you for your reply, I didn't noticed this ! So, in case of non >> square >> matrix with a size that is not a power of 2, should I pad it with zero >> values ? How to get the convolved matrix with the original size after that >> ? >> >> Cheers, >> Pol >> >> 2011/10/14 Michael Schmid <[hidden email]> >> >> Hi Pol, >>> >>> Process>FFT>FD Math (like all FFT functions, except the filters) has >>> periodic boundary conditions, so it is circular convolution. The images >>> have >>> to be square, with both having the same size, and the size must be a >>> power >>> of 2. >>> >>> Michael >>> ______________________________****____________________________**__**____ >>> >>> >>> On 14 Oct 2011, at 17:42, Pol kennel wrote: >>> >>> Hello, >>> >>>> >>>> I would like to know if there is a 2D circular convolution available in >>>> IJ >>>> (or in a plugin). >>>> >>>> Thanks, >>>> Pol >>>> >>>> -- >>>> Pol Kennel >>>> >>>> >>> >> >> -- >> Pol Kennel >> > -- Pol Kennel |
Hi Pol
Image>Adjust>Size is good for both directions. You should probably have the 'Average' checkbox on when converting back. For the small 4x12 size, you might also do it without FFT, as a plain loop, even in a macro. Just use x modulo 4 and y modulo 12 to get the periodic boundary conditions. Roughly like this (I have not tried): setBatchMode(true); xMax=4; yMax=12; // set image ids id1 and id2, create 32-bit output image with id= idOut: // I leave this to you for (dx=0; dx<xMax; dx++) { for (dy=0; dy<yMax; dy++) { sum=0; for (x=0; x<xMax; x++) { for (y=0; y<yMax; y++) { selectImage(id1); v1=getPixel(x,y); selectImage(id2); v2=getPixel((x+dx)%xMax,(y+dy)%yMax); sum+=v1*v2; } } selectImage(id2); setPixel(dx, dy, sum); } } Michael ________________________________________________________________ On 17 Oct 2011, at 10:43, Pol kennel wrote: > Hi Michael, > > Thank you for you attention. > > The thing is I have to convolve a 4x12 features matrix by a 4x12 > mask, not a > image, but anyway. So, using the fft method, I necessarily have to > interpolate my matrices to 16 by 16 ? How to come back to a 4x12 > matrix > after that ? > > I would like to implement the non dft method, but I am not sure of > how it > works in 2D (I think it s ok in 1D) and don't find any explications > on the > web. > > Thank you if you can help me... > > Best regards, > Pol > > > 2011/10/14 Michael Schmid <[hidden email]> > >> Hi Pol, >> >> if you want to take advantage of the periodic boundary conditions, >> don't >> pad it but rather enlarge it to a size that is a power of 2. >> >> If one of your images is smaller than the other one at the desired >> scale >> (by an integer factor, it won't work otherwise), you have to >> replicate the >> smaller one to get the same size. >> One possibility for replication is adding the image repeatedly to >> a stack >> and then using 'Make Montage' with a scale factor of 1 and no >> border or >> labels. >> >> Michael >> ______________________________**______________________________**____ >> >> >> On 14 Oct 2011, at 19:01, Pol kennel wrote: >> >> Hi Michael, >>> >>> Thank you for your reply, I didn't noticed this ! So, in case of non >>> square >>> matrix with a size that is not a power of 2, should I pad it with >>> zero >>> values ? How to get the convolved matrix with the original size >>> after that >>> ? >>> >>> Cheers, >>> Pol >>> >>> 2011/10/14 Michael Schmid <[hidden email]> >>> >>> Hi Pol, >>>> >>>> Process>FFT>FD Math (like all FFT functions, except the filters) >>>> has >>>> periodic boundary conditions, so it is circular convolution. The >>>> images >>>> have >>>> to be square, with both having the same size, and the size must >>>> be a >>>> power >>>> of 2. >>>> >>>> Michael >>>> ______________________________****____________________________**__* >>>> *____ >>>> >>>> >>>> On 14 Oct 2011, at 17:42, Pol kennel wrote: >>>> >>>> Hello, >>>> >>>>> >>>>> I would like to know if there is a 2D circular convolution >>>>> available in >>>>> IJ >>>>> (or in a plugin). >>>>> >>>>> Thanks, >>>>> Pol >>>>> >>>>> -- >>>>> Pol Kennel >>>>> >>>>> >>>> >>> >>> -- >>> Pol Kennel >>> >> > > > -- > Pol Kennel |
Many thanks Michael,
I was not sure about the convolution formula, you kindly fixed me :) It is the same formula as the correlation ? Thank again ! Regards, Pol 2011/10/17 Michael Schmid <[hidden email]> > Hi Pol > > Image>Adjust>Size is good for both directions. You should probably have the > 'Average' checkbox on when converting back. > > For the small 4x12 size, you might also do it without FFT, as a plain loop, > even in a macro. Just use x modulo 4 and y modulo 12 to get the periodic > boundary conditions. > > Roughly like this (I have not tried): > > setBatchMode(true); > xMax=4; > yMax=12; > // set image ids id1 and id2, create 32-bit output image with id= idOut: > // I leave this to you > for (dx=0; dx<xMax; dx++) { > for (dy=0; dy<yMax; dy++) { > sum=0; > for (x=0; x<xMax; x++) { > for (y=0; y<yMax; y++) { > selectImage(id1); > v1=getPixel(x,y); > selectImage(id2); > v2=getPixel((x+dx)%xMax,(y+dy)**%yMax); > sum+=v1*v2; > } > } > selectImage(id2); > setPixel(dx, dy, sum); > } > } > > > > Michael > ______________________________**______________________________**____ > > > On 17 Oct 2011, at 10:43, Pol kennel wrote: > > Hi Michael, >> >> Thank you for you attention. >> >> The thing is I have to convolve a 4x12 features matrix by a 4x12 mask, not >> a >> image, but anyway. So, using the fft method, I necessarily have to >> interpolate my matrices to 16 by 16 ? How to come back to a 4x12 matrix >> after that ? >> >> I would like to implement the non dft method, but I am not sure of how it >> works in 2D (I think it s ok in 1D) and don't find any explications on the >> web. >> >> Thank you if you can help me... >> >> Best regards, >> Pol >> >> >> 2011/10/14 Michael Schmid <[hidden email]> >> >> Hi Pol, >>> >>> if you want to take advantage of the periodic boundary conditions, don't >>> pad it but rather enlarge it to a size that is a power of 2. >>> >>> If one of your images is smaller than the other one at the desired scale >>> (by an integer factor, it won't work otherwise), you have to replicate >>> the >>> smaller one to get the same size. >>> One possibility for replication is adding the image repeatedly to a stack >>> and then using 'Make Montage' with a scale factor of 1 and no border or >>> labels. >>> >>> Michael >>> ______________________________****____________________________**__**____ >>> >>> >>> On 14 Oct 2011, at 19:01, Pol kennel wrote: >>> >>> Hi Michael, >>> >>>> >>>> Thank you for your reply, I didn't noticed this ! So, in case of non >>>> square >>>> matrix with a size that is not a power of 2, should I pad it with zero >>>> values ? How to get the convolved matrix with the original size after >>>> that >>>> ? >>>> >>>> Cheers, >>>> Pol >>>> >>>> 2011/10/14 Michael Schmid <[hidden email]> >>>> >>>> Hi Pol, >>>> >>>>> >>>>> Process>FFT>FD Math (like all FFT functions, except the filters) has >>>>> periodic boundary conditions, so it is circular convolution. The images >>>>> have >>>>> to be square, with both having the same size, and the size must be a >>>>> power >>>>> of 2. >>>>> >>>>> Michael >>>>> ______________________________******__________________________** >>>>> __**__**____ >>>>> >>>>> >>>>> On 14 Oct 2011, at 17:42, Pol kennel wrote: >>>>> >>>>> Hello, >>>>> >>>>> >>>>>> I would like to know if there is a 2D circular convolution available >>>>>> in >>>>>> IJ >>>>>> (or in a plugin). >>>>>> >>>>>> Thanks, >>>>>> Pol >>>>>> >>>>>> -- >>>>>> Pol Kennel >>>>>> >>>>>> >>>>>> >>>>> >>>> -- >>>> Pol Kennel >>>> >>>> >>> >> >> -- >> Pol Kennel >> > -- Pol Kennel |
Hi Pol,
ok, you are right, there is a subtle difference between convolution and correlation, my example was for correlation. In convolution, the argument in one of the functions has a different sign. For convolution, I should have written v2=getPixel((xMax+dx-x)%xMax,(yMax+dy-y)%yMax); (the added xMax, yMax is needed to avoid negative array indices) Michael ________________________________________________________________ On 17 Oct 2011, at 15:27, Pol kennel wrote: > Many thanks Michael, > I was not sure about the convolution formula, you kindly fixed > me :) It is > the same formula as the correlation ? > Thank again ! > Regards, > Pol > > 2011/10/17 Michael Schmid <[hidden email]> > >> Hi Pol >> >> Image>Adjust>Size is good for both directions. You should probably >> have the >> 'Average' checkbox on when converting back. >> >> For the small 4x12 size, you might also do it without FFT, as a >> plain loop, >> even in a macro. Just use x modulo 4 and y modulo 12 to get the >> periodic >> boundary conditions. >> >> Roughly like this (I have not tried): >> >> setBatchMode(true); >> xMax=4; >> yMax=12; >> // set image ids id1 and id2, create 32-bit output image with id= >> idOut: >> // I leave this to you >> for (dx=0; dx<xMax; dx++) { >> for (dy=0; dy<yMax; dy++) { >> sum=0; >> for (x=0; x<xMax; x++) { >> for (y=0; y<yMax; y++) { >> selectImage(id1); >> v1=getPixel(x,y); >> selectImage(id2); >> v2=getPixel((x+dx)%xMax,(y+dy)**%yMax); >> sum+=v1*v2; >> } >> } >> selectImage(id2); >> setPixel(dx, dy, sum); >> } >> } >> >> >> >> Michael >> ______________________________**______________________________**____ >> >> >> On 17 Oct 2011, at 10:43, Pol kennel wrote: >> >> Hi Michael, >>> >>> Thank you for you attention. >>> >>> The thing is I have to convolve a 4x12 features matrix by a 4x12 >>> mask, not >>> a >>> image, but anyway. So, using the fft method, I necessarily have to >>> interpolate my matrices to 16 by 16 ? How to come back to a 4x12 >>> matrix >>> after that ? >>> >>> I would like to implement the non dft method, but I am not sure >>> of how it >>> works in 2D (I think it s ok in 1D) and don't find any >>> explications on the >>> web. >>> >>> Thank you if you can help me... >>> >>> Best regards, >>> Pol >>> >>> >>> 2011/10/14 Michael Schmid <[hidden email]> >>> >>> Hi Pol, >>>> >>>> if you want to take advantage of the periodic boundary >>>> conditions, don't >>>> pad it but rather enlarge it to a size that is a power of 2. >>>> >>>> If one of your images is smaller than the other one at the >>>> desired scale >>>> (by an integer factor, it won't work otherwise), you have to >>>> replicate >>>> the >>>> smaller one to get the same size. >>>> One possibility for replication is adding the image repeatedly >>>> to a stack >>>> and then using 'Make Montage' with a scale factor of 1 and no >>>> border or >>>> labels. >>>> >>>> Michael >>>> ______________________________****____________________________**__* >>>> *____ >>>> >>>> >>>> On 14 Oct 2011, at 19:01, Pol kennel wrote: >>>> >>>> Hi Michael, >>>> >>>>> >>>>> Thank you for your reply, I didn't noticed this ! So, in case >>>>> of non >>>>> square >>>>> matrix with a size that is not a power of 2, should I pad it >>>>> with zero >>>>> values ? How to get the convolved matrix with the original size >>>>> after >>>>> that >>>>> ? >>>>> >>>>> Cheers, >>>>> Pol >>>>> >>>>> 2011/10/14 Michael Schmid <[hidden email]> >>>>> >>>>> Hi Pol, >>>>> >>>>>> >>>>>> Process>FFT>FD Math (like all FFT functions, except the >>>>>> filters) has >>>>>> periodic boundary conditions, so it is circular convolution. >>>>>> The images >>>>>> have >>>>>> to be square, with both having the same size, and the size >>>>>> must be a >>>>>> power >>>>>> of 2. >>>>>> >>>>>> Michael >>>>>> ______________________________******__________________________** >>>>>> __**__**____ >>>>>> >>>>>> >>>>>> On 14 Oct 2011, at 17:42, Pol kennel wrote: >>>>>> >>>>>> Hello, >>>>>> >>>>>> >>>>>>> I would like to know if there is a 2D circular convolution >>>>>>> available >>>>>>> in >>>>>>> IJ >>>>>>> (or in a plugin). >>>>>>> >>>>>>> Thanks, >>>>>>> Pol >>>>>>> >>>>>>> -- >>>>>>> Pol Kennel >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>> -- >>>>> Pol Kennel >>>>> >>>>> >>>> >>> >>> -- >>> Pol Kennel >>> >> > > > -- > Pol Kennel |
Hi Michael,
Thank you again for this precision ! Pol 2011/10/18 Michael Schmid <[hidden email]> > Hi Pol, > > ok, you are right, there is a subtle difference between convolution and > correlation, my example was for correlation. In convolution, the argument in > one of the functions has a different sign. > > For convolution, I should have written > > v2=getPixel((xMax+dx-x)%xMax,(**yMax+dy-y)%yMax); > > (the added xMax, yMax is needed to avoid negative array indices) > > Michael > ______________________________**______________________________**____ > > > On 17 Oct 2011, at 15:27, Pol kennel wrote: > > Many thanks Michael, >> I was not sure about the convolution formula, you kindly fixed me :) It is >> the same formula as the correlation ? >> Thank again ! >> Regards, >> Pol >> >> 2011/10/17 Michael Schmid <[hidden email]> >> >> Hi Pol >>> >>> Image>Adjust>Size is good for both directions. You should probably have >>> the >>> 'Average' checkbox on when converting back. >>> >>> For the small 4x12 size, you might also do it without FFT, as a plain >>> loop, >>> even in a macro. Just use x modulo 4 and y modulo 12 to get the periodic >>> boundary conditions. >>> >>> Roughly like this (I have not tried): >>> >>> setBatchMode(true); >>> xMax=4; >>> yMax=12; >>> // set image ids id1 and id2, create 32-bit output image with id= idOut: >>> // I leave this to you >>> for (dx=0; dx<xMax; dx++) { >>> for (dy=0; dy<yMax; dy++) { >>> sum=0; >>> for (x=0; x<xMax; x++) { >>> for (y=0; y<yMax; y++) { >>> selectImage(id1); >>> v1=getPixel(x,y); >>> selectImage(id2); >>> v2=getPixel((x+dx)%xMax,(y+dy)****%yMax); >>> >>> sum+=v1*v2; >>> } >>> } >>> selectImage(id2); >>> setPixel(dx, dy, sum); >>> } >>> } >>> >>> >>> >>> Michael >>> ______________________________****____________________________**__**____ >>> >>> >>> >>> On 17 Oct 2011, at 10:43, Pol kennel wrote: >>> >>> Hi Michael, >>> >>>> >>>> Thank you for you attention. >>>> >>>> The thing is I have to convolve a 4x12 features matrix by a 4x12 mask, >>>> not >>>> a >>>> image, but anyway. So, using the fft method, I necessarily have to >>>> interpolate my matrices to 16 by 16 ? How to come back to a 4x12 matrix >>>> after that ? >>>> >>>> I would like to implement the non dft method, but I am not sure of how >>>> it >>>> works in 2D (I think it s ok in 1D) and don't find any explications on >>>> the >>>> web. >>>> >>>> Thank you if you can help me... >>>> >>>> Best regards, >>>> Pol >>>> >>>> >>>> 2011/10/14 Michael Schmid <[hidden email]> >>>> >>>> Hi Pol, >>>> >>>>> >>>>> if you want to take advantage of the periodic boundary conditions, >>>>> don't >>>>> pad it but rather enlarge it to a size that is a power of 2. >>>>> >>>>> If one of your images is smaller than the other one at the desired >>>>> scale >>>>> (by an integer factor, it won't work otherwise), you have to replicate >>>>> the >>>>> smaller one to get the same size. >>>>> One possibility for replication is adding the image repeatedly to a >>>>> stack >>>>> and then using 'Make Montage' with a scale factor of 1 and no border or >>>>> labels. >>>>> >>>>> Michael >>>>> ______________________________******__________________________** >>>>> __**__**____ >>>>> >>>>> >>>>> On 14 Oct 2011, at 19:01, Pol kennel wrote: >>>>> >>>>> Hi Michael, >>>>> >>>>> >>>>>> Thank you for your reply, I didn't noticed this ! So, in case of non >>>>>> square >>>>>> matrix with a size that is not a power of 2, should I pad it with zero >>>>>> values ? How to get the convolved matrix with the original size after >>>>>> that >>>>>> ? >>>>>> >>>>>> Cheers, >>>>>> Pol >>>>>> >>>>>> 2011/10/14 Michael Schmid <[hidden email]> >>>>>> >>>>>> Hi Pol, >>>>>> >>>>>> >>>>>>> Process>FFT>FD Math (like all FFT functions, except the filters) has >>>>>>> periodic boundary conditions, so it is circular convolution. The >>>>>>> images >>>>>>> have >>>>>>> to be square, with both having the same size, and the size must be a >>>>>>> power >>>>>>> of 2. >>>>>>> >>>>>>> Michael >>>>>>> ______________________________********________________________**__** >>>>>>> >>>>>>> __**__**____ >>>>>>> >>>>>>> >>>>>>> On 14 Oct 2011, at 17:42, Pol kennel wrote: >>>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> >>>>>>> I would like to know if there is a 2D circular convolution available >>>>>>>> in >>>>>>>> IJ >>>>>>>> (or in a plugin). >>>>>>>> >>>>>>>> Thanks, >>>>>>>> Pol >>>>>>>> >>>>>>>> -- >>>>>>>> Pol Kennel >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>> Pol Kennel >>>>>> >>>>>> >>>>>> >>>>> >>>> -- >>>> Pol Kennel >>>> >>>> >>> >> >> -- >> Pol Kennel >> > -- Pol Kennel |
Free forum by Nabble | Edit this page |