0

I am trying to isolate subimages in a large (6000px wide) jpg file. I managed to customize scikit-image segmentation/labeling example to achieve what I want, but had to resize my image so I don't get MemoryError. Is there a way to get the labeled regions' relative position and use them to crop the original? Here's what the importing and cropping/saving bits of my code look like right now:

image = io.imread("Path\to\image.jpg")
image_small = io.imread("Path\to\image_small.jpg")
image_bw = image_small[:, :, 1]
    def cropper(source):
        count = 1
        for region in regionprops(source):
        # take regions with large enough areas
            if 100000 > region.area >= 1100: 
                minr, minc, maxr, maxc = region.bbox
            # save large enough regions to files
            image_name = "image" + str(count)
            io.imsave(f"{image_name}.jpg", image_small[minr:maxr, minc:maxc])
            count += 1

So ideally I would be able to crop 'image' and not 'image_small'.

Any help will be greatly appreciated!

Martim Passos
  • 137
  • 1
  • 12
  • How do you call the function? What is `source`? – Mad Physicist Jan 17 '20 at 20:53
  • Have you considered scaling the bounds by the ratio of the image sizes and rounding? – Mad Physicist Jan 17 '20 at 20:55
  • @MadPhysicist sorry I edited the code a bit to post it here. `source` would be `image_bw` in this case. I guess scaling the bounds is a good alternative but if I eventually use this with different input sizes it would stop working right? Best option would be to scale `image` to `image_small` within the script so I always know the input/resized ratio, but I don't see how that's possible... – Martim Passos Jan 22 '20 at 19:54

0 Answers0