I can't access pastebin so I paste the code here.

#include "otbCloudDetectionFunctor.h"
#include "otbCloudDetectionFilter.h"

#include "itkMacro.h"
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "otbVectorRescaleIntensityImageFilter.h"
#include "otbMultiChannelExtractROI.h"

int main(int argc, char * argv[])
{

  if (argc != 12)
    {
    std::cerr << "Usage: " << argv[0];
    std::cerr <<
    "inputFileName outputFileName printableInputFileName 
printableOutputFileName";
    std::cerr <<
    "firstPixelComponent secondPixelComponent thirdPixelComponent 
fourthPixelComponent ";
    std::cerr << "variance ";
    std::cerr << "minThreshold maxThreshold " << std::endl;
    return EXIT_FAILURE;
    }

  const unsigned int Dimension = 2;

  typedef double InputPixelType;
  typedef double OutputPixelType;

  typedef otb::VectorImage<InputPixelType, Dimension> VectorImageType;
  typedef VectorImageType::PixelType                  VectorPixelType;
  typedef otb::Image<OutputPixelType, Dimension>      OutputImageType;

  typedef otb::Functor::CloudDetectionFunctor<VectorPixelType,
      OutputPixelType>   FunctorType;

  typedef otb::CloudDetectionFilter<VectorImageType, OutputImageType,
      FunctorType> CloudDetectionFilterType;

  typedef otb::ImageFileReader<VectorImageType> ReaderType;
  typedef otb::ImageFileWriter<OutputImageType> WriterType;

  ReaderType::Pointer               reader = ReaderType::New();
  CloudDetectionFilterType::Pointer cloudDetection =
    CloudDetectionFilterType::New();
  WriterType::Pointer writer = WriterType::New();

  reader->SetFileName(argv[1]);
  cloudDetection->SetInput(reader->GetOutput());
  
  /* Added code */
  OutputImageType::IndexType pixelIndex;
  pixelIndex[0] = 0;
  pixelIndex[1] = 0;
  unsigned short int pixelValue;
  for (int i = 0; i < 4; i++) {
pixelValue = cloudDetection->GetInput()->GetPixel(pixelIndex)[i];
std::cout << "GetPixel[" << i << "] = " << pixelValue << std::endl;
  }
  /* End added code */  

  VectorPixelType referencePixel;
  referencePixel.SetSize(4);
  referencePixel.Fill(0.);
  referencePixel[0] = (atof(argv[5]));
  referencePixel[1] = (atof(argv[6]));
  referencePixel[2] = (atof(argv[7]));
  referencePixel[3] = (atof(argv[8]));
  cloudDetection->SetReferencePixel(referencePixel);

  cloudDetection->SetVariance(atof(argv[9]));

  cloudDetection->SetMinThreshold(atof(argv[10]));
  cloudDetection->SetMaxThreshold(atof(argv[11]));

  writer->SetFileName(argv[2]);
  writer->SetInput(cloudDetection->GetOutput());
  writer->Update();

  typedef otb::Image<unsigned char,
      Dimension>
  OutputPrettyImageType;
  typedef otb::VectorImage<unsigned char,
      Dimension>
  InputPrettyImageType;
  typedef otb::ImageFileWriter<OutputPrettyImageType>
  WriterPrettyOutputType;
  typedef otb::ImageFileWriter<InputPrettyImageType>
  WriterPrettyInputType;
  typedef itk::RescaleIntensityImageFilter<OutputImageType,
      OutputPrettyImageType>
  RescalerOutputType;
  typedef otb::VectorRescaleIntensityImageFilter<VectorImageType,
      InputPrettyImageType>
  RescalerInputType;
  typedef otb::MultiChannelExtractROI<InputPixelType,
      InputPixelType>
  ChannelExtractorType;

  ChannelExtractorType::Pointer  selecter           = 
ChannelExtractorType::New();
  RescalerInputType::Pointer     inputRescaler     = 
RescalerInputType::New();
  WriterPrettyInputType::Pointer prettyInputWriter = 
WriterPrettyInputType::New();
  selecter->SetInput(reader->GetOutput());
  selecter->SetChannel(3);
  selecter->SetChannel(2);
  selecter->SetChannel(1);
  inputRescaler->SetInput(selecter->GetOutput());
  VectorPixelType minimum, maximum;
  minimum.SetSize(3);
  maximum.SetSize(3);
  minimum.Fill(0);
  maximum.Fill(255);
  inputRescaler->SetOutputMinimum(minimum);
  inputRescaler->SetOutputMaximum(maximum);
  prettyInputWriter->SetFileName(argv[3]);
  prettyInputWriter->SetInput(inputRescaler->GetOutput());

  RescalerOutputType::Pointer     outputRescaler     = 
RescalerOutputType::New();
  WriterPrettyOutputType::Pointer prettyOutputWriter =
    WriterPrettyOutputType::New();
  outputRescaler->SetInput(cloudDetection->GetOutput());
  outputRescaler->SetOutputMinimum(0);
  outputRescaler->SetOutputMaximum(255);
  prettyOutputWriter->SetFileName(argv[4]);
  prettyOutputWriter->SetInput(outputRescaler->GetOutput());

  prettyInputWriter->Update();
  prettyOutputWriter->Update();

  return EXIT_SUCCESS;
}




Le mardi 29 avril 2014 08:49:12 UTC+1, Rashad a écrit :
>
> Hi,
>
> Could you post the your full code on pastebin.com ?
>
>
> On Tue, Apr 29, 2014 at 9:46 AM, OTB Florian <[email protected]<javascript:>
> > wrote:
>
>> Thanks for your explanation.
>> I've changed the values to 0 as you proposed but now I get a segmentation 
>> fault when calling the GetPixel() method.
>>
>> Le mardi 29 avril 2014 08:31:07 UTC+1, Rashad a écrit :
>>>
>>> Hi,
>>>
>>>
>>> On Tue, Apr 29, 2014 at 9:17 AM, OTB Florian <[email protected]> wrote:
>>>
>>>> Hi,
>>>>
>>>> 337300 and 7674920 are just the coordinates of the image origin I got 
>>>> with otbcli_ReadImageInfo command or by adding the line
>>>> std::cout << cloudDetection->GetInput()->GetOrigin() << std::endl;
>>>> in the code.
>>>>
>>>
>>> This is wrong. You are confused with image pixels and image coordinates 
>>> here. What you are talking about is the projected coordinates of image. 
>>>
>>> Image pixels starts with 0,0 is most image processing software. IIRC, 
>>> Matlab is an exception in this case. But anyway here if you are trying to 
>>> get the pixel for the entire image, the best thing is to use image 
>>> iterators which gives you efficient access to pixels.
>>>
>>> If you want to get a single pixel as you mentioned in your case. 
>>>
>>> The image pixels starts with 0,0 and end with (width-1, height-1)
>>>
>>> pixelIndex[0] = 0
>>> pixelIndex[1] = 0
>>>
>>>  
>>> And for another case if you want to get a pixel at a particular 
>>> coordinates 
>>> say you only know lat,lon -> You need to find the corresponding pixel 
>>> location based on the projection and use it.
>>>
>>>
>>>>
>>>> Le lundi 28 avril 2014 17:09:08 UTC+1, Rashad a écrit :
>>>>>
>>>>> Hi,
>>>>>
>>>>>
>>>>> On Mon, Apr 28, 2014 at 10:49 AM, OTB Florian <[email protected]>wrote:
>>>>>
>>>>>> Hi Rashad,
>>>>>>
>>>>>> Thanks for your reply.
>>>>>> I've tested all the examples you recommanded to me.
>>>>>>
>>>>>> I'm still working on the cloud detection example and always 
>>>>>> experimenting the same problem.
>>>>>> I've just added theses code lines after cloudDetection->SetInput(
>>>>>> reader->GetOutput()); (l.157 : https://github.com/echristophe
>>>>>> /OTB/blob/master/Examples/FeatureExtraction/CloudDetectionExample.cxx) 
>>>>>> :
>>>>>>
>>>>>> OutputImageType::IndexType pixelIndex;
>>>>>> pixelIndex[0] = 337300;
>>>>>> pixelIndex[1] = 7674920;
>>>>>> unsigned short int pixelValue;
>>>>>> for (int i = 0; i < 4; i++) { // cause it's a 4-band image
>>>>>>    pixelValue = cloudDetection->GetInput()->GetPixel(pixelIndex)[i];
>>>>>>    std::cout << "GetPixel[" << i << "] = " << pixelValue << std::endl;
>>>>>>  }
>>>>>>
>>>>>>
>>>>>> Then I get senseless values which are different at each execution.
>>>>>>
>>>>>>
>>>>>
>>>>> How do you find the pixelIndex in the code?
>>>>>
>>>>> pixelIndex[0] = 337300;
>>>>> pixelIndex[1] = 7674920;
>>>>>
>>>>> Could you please elaborate the calculation of  "337300" and "7674920" ?
>>>>>  
>>>>>
>>>>>> Any idea?
>>>>>>
>>>>>> Thanks in advance.
>>>>>>
>>>>>>
>>>>>> Le vendredi 25 avril 2014 11:11:08 UTC+1, Rashad a écrit :
>>>>>>>
>>>>>>> Hi OTB,
>>>>>>>
>>>>>>>
>>>>>>> On Fri, Apr 25, 2014 at 11:50 AM, OTB Florian <[email protected]>wrote:
>>>>>>>
>>>>>>>>
>>>>>>>> Hi all!
>>>>>>>>
>>>>>>>> I'm new at OTB and studying some examples to become familiar with 
>>>>>>>> the library.
>>>>>>>>
>>>>>>>>
>>>>>>> You might start with the first example - 
>>>>>>> http://www.orfeo-toolbox.org/SoftwareGuide/SoftwareGuidech4.html
>>>>>>>  
>>>>>>>
>>>>>>>> I've tried the cloud detection example (https://github.com/
>>>>>>>> echristophe/OTB/blob/master/Examples/FeatureExtraction/CloudDetecti
>>>>>>>> onExample.cxx) with the CloudsOnReunion.tif file and it works very 
>>>>>>>> well.
>>>>>>>> However, I'm facing some difficulties while trying to get the 
>>>>>>>> values of the different (4) bands of a pixel via the GetPixel() method.
>>>>>>>>
>>>>>>>
>>>>>>> Could you post some of your code which you tried?.
>>>>>>>  
>>>>>>>
>>>>>>>> I'm wondering the type returned by this method. In that case, I get 
>>>>>>>> an array with four values which don't mean anything (NaN or values 
>>>>>>>> around 
>>>>>>>> 1e-154).
>>>>>>>> Behind this trouble is the way of encoding the band intensities. Is 
>>>>>>>> there any function to know the type of encoding, the min and max of 
>>>>>>>> each 
>>>>>>>> band?
>>>>>>>>
>>>>>>>
>>>>>>> I think you must try the examples first. Sources are available here 
>>>>>>> - http://hg.orfeo-toolbox.org/OTB/file/fc0c18977f12/Examples
>>>>>>> /Tutorials
>>>>>>>
>>>>>>> [1] http://www.orfeo-toolbox.org/SoftwareGuide/SoftwareGuidech4.html
>>>>>>>  
>>>>>>>
>>>>>>>>  
>>>>>>>>
>>>>>>>  
>>>>>>>> If you could help me...
>>>>>>>>
>>>>>>>> Thanks.
>>>>>>>>
>>>>>>>> -- 
>>>>>>>> -- 
>>>>>>>> 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/d/optout.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> -- 
>>>>>>> Regards,
>>>>>>>    Rashad
>>>>>>>  
>>>>>>  -- 
>>>>>> -- 
>>>>>> 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/d/optout.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -- 
>>>>> Regards,
>>>>>    Rashad
>>>>>  
>>>>  -- 
>>>> -- 
>>>> 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/d/optout.
>>>>
>>>
>>>
>>>
>>> -- 
>>> Regards,
>>>    Rashad
>>>  
>>  -- 
>> -- 
>> 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/d/optout.
>>
>
>
>
> -- 
> Regards,
>    Rashad
>  

-- 
-- 
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/d/optout.

Reply via email to