Reputation: 35
Just trying to understand how a piece of Python code works. The code in question modifies the dimensions of a numpy array using cv2.resize. I would like to know the way that opencv modifies the array in order to populate the new dimensions of the array. I'm trying to translate this into C#, so any psuedocode in an explanation would also be appreciated.
print(last_heatmap.shape) --> [32,32,21]
print(type(last_heatmap)) --> numpy.ndarray
last_heatmap = cv2.resize(last_heatmap, (256,256))
print(last_heatmap.shape) --> [256,256,21]
print(type(last_heatmap)) --> numpy.ndarray
I'm looking for a understanding of how this particular function works, as a bonus suggestions about how to replicate this in other languages (for c#, perhaps an 3d-array of floats?). Thanks.
Upvotes: 0
Views: 390
Reputation: 11232
OpenCV’s resize does not actually modify the array, it creates a completely new one. The documentation for the function can be found here.
For each pixel in the destination array it will scale its coordinates to match the size of the source array. The pixel at the mapped coordinate will be looked up in the source array and written to the destination. By default it does a bilinear interpolation, considering averaged sub pixel values.
Image scaling is a common operation. You will not have to reimplement this in C# and can instead rely on libraries.
Upvotes: 1