Label Shape Opening Slice by Slice not working very welll

Can’t apply shape open slice by slice. I get a null image, even though most of the connected components have less than 1000 pixels…

for(int slice_to_process = 0; slice_to_process < final_slice_ribs ; slice_to_process++){

                ImageType::RegionType inputRegion_ribs = image_ribs_extraction->GetBufferedRegion();
                reader_ribs_4->Update();
                ImageType::SizeType   size_ribs = inputRegion_ribs.GetSize();
                
                size_ribs[2] = 1; // we extract along z direction
                
                ImageType::IndexType start_ribs = inputRegion_ribs.GetIndex();
                
                int  sliceNumber_ribs = slice_to_process + start_ribs[2];
              
                start_ribs[2] = sliceNumber_ribs;
                
                ImageType::RegionType desiredRegion_ribs;
                desiredRegion_ribs.SetSize(size_ribs);
                desiredRegion_ribs.SetIndex(start_ribs);
                
                auto extractFilter_ribs = ExtractFilterType_Ribs::New();
                extractFilter_ribs -> SetDirectionCollapseToSubmatrix();
                extractFilter_ribs->SetExtractionRegion(desiredRegion_ribs);
              extractFilter_ribs->SetInput(image_ribs_extraction);
                extractFilter_ribs->Update();
                 
                                    
            auto connected_ribs = ConnectedComponentImageFilterType_Ribs::New();
            connected_ribs->SetInput(extractFilter_ribs->GetOutput());
              connected_ribs->Update();

           std::cout  << connected_ribs->GetObjectCount();  
           
               std::cout<<"  ";

             
                auto i2l_ribs = i2lType_Ribs::New();
                i2l_ribs->SetInput(connected_ribs->GetOutput());
                i2l_ribs->Update();

     
            
        //   attribute    Number of Pixels  100

       // Remove label objects that have spherical diameter higher than higher_diameter_threshold
                    
             
             // static constexpr  LabelOpeningType::AttributeType attribute_ribs = 100;
                                   
              auto shapeOpening_ribs = LabelOpeningType_Ribs::New();
              shapeOpening_ribs->SetInput(i2l_ribs->GetOutput());
              shapeOpening_ribs->SetLambda(1000);
              shapeOpening_ribs->ReverseOrderingOn();
              shapeOpening_ribs->SetAttribute(100);
              shapeOpening_ribs->Update();
        

             
       auto labelMapToLabelImageFilter_ribs = LabelMapToLabelImageFilterType_Ribs::New();
       labelMapToLabelImageFilter_ribs ->SetInput(shapeOpening_ribs->GetOutput());
       labelMapToLabelImageFilter_ribs->Update();   
       
               
               const ImageType * image_to_paste_ribs = labelMapToLabelImageFilter_ribs->GetOutput();
               labelMapToLabelImageFilter_ribs->Update();

               auto pasteFilter_ribs = PasteFilterType_Ribs::New();
               pasteFilter_ribs->SetSourceImage(labelMapToLabelImageFilter_ribs->GetOutput());
               pasteFilter_ribs->SetSourceRegion(image_to_paste_ribs->GetBufferedRegion());
               pasteFilter_ribs->SetDestinationImage(image_ribs_final);
               pasteFilter_ribs->SetDestinationIndex(start_ribs);
               pasteFilter_ribs->Update();
          
          
                        }
                        
                        
                          
            auto writer_ribs = WriterType_Ribs::New();
            writer_ribs->SetFileName("Ribs.dcm");
            writer_ribs->SetInput(image_ribs_final);
            writer_ribs->SetImageIO(dicomIO);
            writer_ribs->Update();