0

Hello all I ran into this error when I tried to display an via imshow: Invalid shape (4951,) for image data

This data is the pixel "peak_vals" output I got from running an image through photutils.find_peaks(). The original shape was (5820,). I'm pretty sure this error is occurring because of the irregular shape, but I am not sure if it is possible to reshape it to the right dimensions.

So my question is:

  1. If there is a possible method of reshaping, what is it?

  2. If no, how can I find the connected pixels (or hyperpixels) within the image that I am working with? My original approach was to fit the peak_vals data (pixel intensity data) to an ellipse and filter down the data/pixels to those that fit within the ellipse. 2 iterations of this led to the data's reshaping (from (5820,) to (4951,).

  • 1
    From the [`imshow` documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.imshow.html): the input data must have either array shapes `(M, N)`, `(M, N, 3)`, or `(M, N, 4)`. Therefore, it must contain at least two dimensions describing the rows and columns. Your `peak_vals` variable has only one dimension. Are you sure you want to visualise it using `imshow`? Please show more of your code or an example input to give us an idea what you want to achieve. – luuk Mar 19 '21 at 21:29
  • Hey luuk thanks for the reply. After further analyzing my problem, visualizing the (4951,) data is probably not what I want to do. I was able to visualize the data I inputted to `find_peaks()` to get the (5820,). This original input data was a 1004 x 1004 np.array that could be visualized with `imshow`. So, I guess what I am trying to do is link the filtered down `peak_vals` back to the output of the `find_peaks(np.array(1004 x 1004))` function, but I shall work on it longer and update this post with the appropriate code and data. – Marcelino Velasquez Mar 20 '21 at 21:48

0 Answers0