Find_Peaks: Invalid shape (4951,) for image data. Possible solutions? - python

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:
If there is a possible method of reshaping, what is it?
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,).

Related

Promblem to use iradon on image with the shape of (168,400)

I want to implement iradon. Radon image shape is (168,400).
But when I implement iradon on it the image shape become (168,168)!!!
I want to have an image with (168,400) shape.
Where is the problem?
Image = iradon (radon_image, filter_name=None)
I read the instruction on:
https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.iradon
; but I did not understand the problem.
I really appreciate if anyone can help me.
I think you might be mis-understanding how the Radon (and inverse Radon) transform work.
The size of your radon_image is (number of pixels in original image, number of projections). So in your example, the image is 168 pixels across with 400 different projections (see image below from the scikit-image website). Therefore, when you perform the inverse Radon transform you will get an image with a size of 168 pixels.
Perhaps if you explain further why you want the resulting image with a particular size, it will be possible to help further.

How do I properly mask values in my Convolutional Neural Network

I'm creating an encoder-decoder CNN for some images. Each image has a geometric shape around the center - circle, ellipse, etc.
I want my CNN to ignore all the values that are in this shape. All my input data values have been normalized to be around 0-1. I set all the shape values to be 0.
I thought that setting them to zero would mean that they will not be updated, however, the output of my encoder-decoder CNN changes the shape.
What can I do to ensure these values stay put and do not update?
Thank you!
I think you are looking for "partial convolution". This is a work published by Guilin Liu and colleagues that extends convolution to take an input mask as well as an input feature map and apply the convolution only to the unmasked pixels. They also suggest how to compensate for pixels on the boundary of the mask, where the kernel "sees" both valid and masked-out pixels.
Please note that their implementation may have issues running with automatic mixed precision (AMP).

How to (generally!) deal with out-of-range output pixel destinations

I'm working on a perspective transform application involving transforming 3D points to 2D camera pixels. It is a purely mathematical model, because I'm preparing to use it on hardware that I don't really have access to (so I'm making up focal length and offset values for the intrinsic camera matrix).
When I do the mapping, depending on the xyz location of the camera, I get huge differences in where my transformed image is, and I have to make the matrix where I'm inputting the pixels really large. (I'm mapping an image of 1000x1000 pixels to an image of about 600x600 pixels, but its located around 6000, so I have to make my output matrix 7000x7000, which takes a long time to plt.imshow. I have no use for the actual location of the pixels, because I'm only concerned with what the remapped image looks like.
I was wondering how people dealt with this issue:
I can think of just cropping the image down to the area that is non-zero (where my pixels are actually mapped too? Like seen in:
How to crop a numpy 2d array to non-zero values?
but that still requires me to use space and time to alot a 7000x7000 destination matrix

image line detection for a grayscale image .. not working

Input image
This is a 3000x3000 greyscale image, and I would like to get the coordinates of the diagonal components in the image.
I tried Hough transform and pylsd (line segment detection), but both of them don't work as I hoped. Here are some unsatisfactory outcomes:
result with too many junks
I would like to have a maximum amount of true diagonals with minimum number of junks by using a simple parameter such as the length above which a cluster can be labeled as a line. Any suggestions or tips will be appreciated.
Either Python or R is preferred (not matlab)

Cant display the LBP image after using exposed elbp function in python

I am trying to display an lbp image after applying elbp function to a gray-scale image, the function was exposed manually in the face module for python.
here's the code:
LBP = cv2.face.elbp(gray_roi,1,8)
cv2.imshow("Face",LBP)
But however, what I got is a pure black window,also I noticed that the cols and rows are always smaller than the original image by 2,here is the error information:
could not broadcast input array from shape (95,95) into shape (97,97)
I noticed one other ppl asked the same question but was using c++ instead: Unable to display image after applying LBPH (elbp()) operator in opencv
But what I cant understand is what he meant by normalized the image to fit the screen rendering range?
here is the matrix ouput of my image:
print(LBP)
As you can see, the pixel intensity distribution is normal.
here is the actual elbp function!
#barny thx for your detailed response , based on your solution, I times the matrix by a value like 64, finally I got the image shown, but I'm not sure why do I have to times a value to get the proper visible image,shouldn't it be done in the original elbp function?
and also , the matrix element value become very large:
here is some part of the histogram that I printed out from the shown image(times a value by 64):
histogram=scipy.stats.itemfreq(LBP1)
print(histogram)[[ 0 1726]
histogram
If someone can explain to me why do I have to multiply such a big value that would be great!
ps:this is my 1st time ask on stack overflow, thx for everyone who tried to help !

Categories