Author Topic: PCL as image processing library  (Read 3642 times)

Offline Aleix Puig

  • Newcomer
  • Posts: 5
PCL as image processing library
« on: 2018 October 12 01:00:56 »
Hi,

I am trying to use PCL as an image processing library linking it in another application outside PixInsight, like I would do with OpenCV. I am not sure if PCL can actually work without the PixInsight core. If it is possible, how do I have to initialize the library? do you have an example? The library compiles and links but I am having some troubles executing since the API pointer is null and the initialization seems to be called from the core.

Thanks!

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PCL as image processing library
« Reply #1 on: 2018 October 12 02:49:48 »
Hi Aleix,

Most of PCL can work without a running PixInsight core application. The exceptions are basically all classes related to the user interface (UIObject and all derived classes) and a few purely numerical classes where the underlying functionality is provided by the core application (CubicSplineInterpolation, SurfaceSpline, LinearFit and SVD, if I remember well). With the exception of XISF, which is completely implemented in PCL, the rest of file formats depend on installed modules, so you also need a running core to open, for example, a TIFF file. Other than these, the rest of PCL is completely autonomous.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Aleix Puig

  • Newcomer
  • Posts: 5
Re: PCL as image processing library
« Reply #2 on: 2018 October 15 06:55:07 »
Hi Juan,

That's nice, but do I have to initialize the library? Just for testing I am calling Rotate180() but it tries to access API->Thread which is nullptr:

/*
 * ### TODO: Implement pcl::Thread without core application support, in case
 * we are running as an independent application.
 *
 * For now, we simply construct a null object when API = nullptr. The
 * reimplemented Thread::Run() can be invoked single-threaded.
 */

Thread::Thread() :
   UIObject( (API != nullptr) ? (*API->Thread->CreateThread)( ModuleHandle(), this, 0/*flags*/ ) : nullptr )
{
   if ( API != nullptr )
   {
      if ( IsNull() )
         throw APIFunctionError( "CreateThread" );

      (*API->Thread->SetThreadExecRoutine)( handle, ThreadDispatcher::RunThread );

      if ( s_featureDataInitialized.Load() == 0 )
      {
         /*
          * ### TODO: Add a new StartThreadEx() API function to allow
          * specifying a logical processor index and other flags. In this way
          * this wouldn't be necessary and thread scheduling and affinity would
          * be controlled completely by the core application.
          */
         static Mutex mutex;
         volatile AutoLock lock( mutex );
         if ( s_featureDataInitialized.Load() == 0 )
         {
            s_enableAffinity = PixInsightSettings::GlobalFlag( "Process/EnableThreadCPUAffinity" );
            s_featureDataInitialized.Store( 1 );
         }
      }
   }
}

Aleix

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PCL as image processing library
« Reply #3 on: 2018 October 15 11:52:06 »
Hi Alex,

Thread is a derived class of pcl::UIObject, so it needs a running PixInsight core application. However, as you see in the code, I modified its normal behavior as an exception to allow instantiation of Thread objects without core communication, so it should work single threaded in such cases, modulo bugs.

As noted in the source code comment, my intention is to implement an independent back end for the Thread class to support standalone PCL-based applications (probably around the std::thread class). However, please understand that this is not a priority, since the primary purpose of PCL is building PixInsight modules.

Rotate180 does not use threads by itself, so the problem you are getting must come from elsewhere. Can you share relevant parts of your code?
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Aleix Puig

  • Newcomer
  • Posts: 5
Re: PCL as image processing library
« Reply #4 on: 2018 October 16 04:51:25 »
Hi Juan,

My code is pretty simple:

Code: [Select]
pcl::FImage pclImage;
float* p = f32VipImage.ptr();
pclImage.ImportData(&p, f32VipImage.shape(1), f32VipImage.shape(0));
pcl::Rotate180() >> pclImage;
pclImage.ReleaseData();

It looks like it is trying to monitor a thread which is null (see the attachment). It would be nice to have the alternative implementation of Thread, but I understand that it is not a priority for you.

Aleix

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PCL as image processing library
« Reply #5 on: 2018 October 16 05:05:31 »
Hi Aleix,

Try this:

pclImage.Status().DisableInitialization();
pclImage.DisableParallelProcessing();


before executing Rotate180. It should not try to use any thread this way. Let me know if it works.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Aleix Puig

  • Newcomer
  • Posts: 5
Re: PCL as image processing library
« Reply #6 on: 2018 October 16 05:53:04 »
Oh, I have just seen that I can disable this.

Aleix

Offline Aleix Puig

  • Newcomer
  • Posts: 5
Re: PCL as image processing library
« Reply #7 on: 2018 October 16 14:03:51 »
Hi Juan,

The rotation works fine, but now I am trying to do a MultiscaleLinearTransform. The same exception happens with the status monitoring. My code:

float* p = f32VipImage.ptr();

m_pclImage.ImportData(&p, f32VipImage.shape(1), f32VipImage.shape(0));

m_pclImage.Status().DisableInitialization();
m_pclImage.DisableParallelProcessing();

m_transform.SetDyadicScalingSequence();
m_transform.SetNumberOfLayers(6);
m_transform.DisableParallelProcessing();

m_transform << m_pclImage;

Apparently, the MLTDecomposition is monitoring the status when computing the different layers. How can I disable the status monitoring of the internal operations of this process?

Aleix