2

I have a very large dataset in the form of 2D array/matrix (i and j, 125 * 125) which when I plot these values in a 2D plot, I can see several patterns and shapes at specific region of the plot. I am trying to use the same data but to rotate the data in the matrix (so that those patterns seen in the plot can be clearly rotated while keeping same data), let's say by 10 degrees clockwise. is there anyway that I can do this using Python? In other words, I would like the position of those coordinates of every point move in a way that can give us a rotated version of the original plot, if that makes sense, such that after comparing the two plots, one can clearly see that the new plot is a rotated version of the same data.

I have attached a sample dataset. My simulation software reads the data in every row from left to right, right to left, left to right,... until reaching the end of the data.

illustration of problem

3
  • Welcome to Stack Overflow. Good question, but I am not totally clear on what you want — the result of the transformation, or something more like new pixel positions in some coordinate space resulting from an affine transformation. Commented Sep 4, 2021 at 12:50
  • The problem is that there is not a direct 1-1 match of the grid. Actually, to be more precise, there is a bijection, but all distort the discretized space. Thus, you certainly need to interpolate the cells. This interpolation does not always make sense regarding the input data. The interpolation algorithm can change regarding the input data because some properties need to be conserved (eg. energy, impulse, etc.). If you do not care about this and all the values are 0<x<256, you can use any imaging library providing this feature (OpenCV, PIL, etc.). Commented Sep 5, 2021 at 10:50
  • Please provide enough code so others can better understand or reproduce the problem. Commented Sep 8, 2021 at 0:52

1 Answer 1

1

It sounds like you might be looking for scipy.ndimage.rotate(). The ndimage module is awesome — you can do a lot of 'imagey' things to ndarrays.

You would want reshape=True I think to ensure that you do not lose data. From the docs:

>>> from scipy import ndimage, misc
>>> img = misc.ascent()
>>> rot_45 = ndimage.rotate(img, 45, reshape=True)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.