How is the image resizing done in my project's input/image blocks?

Hi,

I’ve been working on an image classification project (24610). All of my images are 96x96 pixels. I wanted to convert them to 48x48 using the “Crop” feature in the input block. For some reason, the option for “Crop” was not showing up, so I chose “Fit shortest axis”, curious about how the block would process the image. In the image block below “Create Impulse”, I can see (in RGB mode) that the processed images are smaller and lower quality, but have not been cropped. How are the blocks resizing the images? I would like to recreate this in an Arduino sketch. I’ve seen the “Crop” option in other projects before and I wanted to use it, but the neural network was still producing good results with “Fit shortest axis” selected.

Thanks.

Any other information I can provide? Maybe there’s a way to get the “Crop” feature back?

Hi @s-agar So there are three resize mechanisms, two of which who crop, and one which squashes the image. We’ve removed the ‘crop’ function because it was misleadingly named. Let me show you the three options:

Original

Squash

image

This just squashes the image so it fits into the set size.

Fit shortest axis

image

This crops the image so that the shortest axis (here the y axis as the width is larger than height) will fit, and the remainder is cut off. So you keep the center. This is typically what you want (and our firmware also implements this, see e.g. https://github.com/edgeimpulse/example-portenta-lorawan/blob/eec5c3e258f55ac656e15a1d456ac6eca770c3ff/src/sensors/ei_camera.cpp#L186

Fit longest axis

image

This fits the longest axis in the picture (here the x axis) and then adds padding so the aspect ratio remains the same.

Summary

You probably want fit shortest axis, it auto-crops.

2 Likes

Hi @janjongboom, thanks for the information. Since the images in my project have the same width and height, how would the “Fit shortest axis” option crop/resize the image? Also, I am using an Arduino Nano 33 BLE Sense, so could I port the cropImage() or resizeImage() functions to it?

If it’s the same width & height already it does not matter. They will all resize the same way.

Also, I am using an Arduino Nano 33 BLE Sense, so could I port the cropImage() or resizeImage() functions to it?

Yes, the resizeImage function should work as-is.

1 Like

Hi @janjongboom, Same subject, I am trying to find if there is an example to define a ROI in the GitHub - edgeimpulse/processing-blocks: Signal processing blocks. But couldn’t find any to try out. What I am trying to do is to ROI only the lighted digits area to say if the water heater is on/off. If you have an example to accomplish this, could you suggest? My project id is: 194971
Thanks.
no water
water