Hi Agustin,

I have a short python example (not tested) which computes the mean of 2 
multispectral images by looping over the number of bands, using the 
BandMath application and then concatenates the results. You may want to 
adapt it in order to apply it to a list of images.

import otbApplication as otb

def multispectralAdd(im1, im2, nbBands, outputName):
    tmpImageName = "/tmp/ma" #prefix for temp files
    tmpImages = []                    #list to hold the temp images
    for band in range(nbBands):       #we add band by band
        tmpImages.append(tmpImageName+str(band)+".tif")
        bm = otb.Registry.CreateApplication("BandMath")
        bm.SetParameterStringList("il", [im1, im2])
        bm.SetParameterString("out", tmpImages[-1])
        bm.SetParameterString("exp", 
"(im1b"+str(band)+"+im2b"+str(band)+")/"+str(nbBands))
        bm.ExecuteAndWriteOutput()

    #and we concatenate all the temp files
    concat = otb.Registry.CreateApplication("ConcatenateImages")
    concat.SetParameterStringList("il", tmpImages)
    concat.SetParameterString("out", outputName)
    concat.ExecuteAndWriteOutput()


And maybe my example can be used with the reduce function 
http://docs.python.org/2/library/functions.html#reduce

I hope this helps.

Bon Nadal.

Jordi

On Friday, December 20, 2013 3:11:49 PM UTC+1, alobo wrote:
>
> Merci! 
>
> I will try, although would prefer a shell or python solution. 
> I'm also looking at simplecv, although it seems that reading 
> images > 3 bands is not easy. 
>
> Have a nice Xmas season! 
>
> Agus 
>
> On Fri, Dec 20, 2013 at 10:11 AM, Julien Malik 
> <[email protected]<javascript:>> 
> wrote: 
> > Hi Agus, 
> > 
> > I don't see a straight forward way to do this with otb_cli or otb-python 
> > (there might be one), but this is a very easy one if you are not afraid 
> > of writing a bit a C++. 
> > I would do it like this : 
> > - build up a VRT concatenating all the images with GDAL. 
> > - write a very simple pipeline Reader->MatrixImageFilter->Writer. 
> > - building up your transformation accordingly. N being you number of 
> > images, this would be a 6N x N matrix filled with (1/N) at the right 
> places. 
> > 
> > Actually the code you need is already written in a test : 
> > 
> http://hg.orfeo-toolbox.org/OTB/file/6211d0ccba0f/Testing/Code/BasicFilters/otbMatrixImageFilterTest.cxx#l40
>  
> > You just have to adapt the matrix size and filling. 
> > 
> > It would be multithreaded and streamed. 
> > This would give you very decent performances I think. 
> > 
> > You can follow this : 
> > 
> http://www.orfeo-toolbox.org/SoftwareGuide/SoftwareGuidech2.html#x14-330002.3 
> > for instructions on how to build the CMakeLists that will compile your 
> > project. 
> > 
> > Cheers, 
> > Julien 
> > 
> > 
> > On 12/19/2013 01:14 PM, Agustin Lobo wrote: 
> >> I have to calculate the average multi-spectral image (6 bands) 
> >> over a set of ~100 images (6x1024x1280). That is, having 3 
> multiespectal 
> >> images A,B and C, I need M in which band1 is the average band1 of A, B 
> and C 
> >> and so on. Also, I first subtract the mean for each band. 
> >> 
> >> I currently do this in R, but takes a very long time. I essentially 
> >> make an stack (which is like a vrt file) with all bands and then 
> >> calculate the average of bands 1,7,13... 
> >> 2,8, 14... etc 
> >> Is there a way of making this 
> >> calculation using either otb_cli or python-otb ? 
> >> 
> >> Thanks 
> >> 
> >> Agus 
> >> 
> > 
> > -- 
> > -- 
> > Check the OTB FAQ at 
> > http://www.orfeo-toolbox.org/FAQ.html 
> > 
> > You received this message because you are subscribed to the Google 
> > Groups "otb-users" group. 
> > To post to this group, send email to [email protected]<javascript:> 
> > To unsubscribe from this group, send email to 
> > [email protected] <javascript:> 
> > For more options, visit this group at 
> > http://groups.google.com/group/otb-users?hl=en 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups "otb-users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to [email protected] <javascript:>. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
>

-- 
-- 
Check the OTB FAQ at
http://www.orfeo-toolbox.org/FAQ.html

You received this message because you are subscribed to the Google
Groups "otb-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/otb-users?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"otb-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to