Avoiding empty blocks in a layout

Hello,

I’m implementing a slider in my page, and with this current snippet I’m able to remove those rows in the layout that are empty. But I would also like to remove those ones that are having an empty block inside (ie. an image field without any selected image) to avoid blank slides.

I’m trying to access the blocks before creating the slide but I can’t seem to manage to do it.
Is there a way to do that?

Thanks a lot!

  <?php foreach ($page->layout()->toLayouts() as $layout): ?>

      <?php if($layout->isNotEmpty()): ?>
        <div class="slide">
          <div class="block">
          <?php foreach ($layout->columns() as $column): ?>
            <div class="item">
              <?= $column->blocks() ?>
            </div>
          <?php endforeach ?>
          </div>
        </div>
        <?php endif ?>

      <?php endforeach ?>

Instead of echoing the blocks, you can loop through the individual blocks