admin管理员组文章数量:1291566
I am trying to detect the fringes/edges of the following image but it doesn't work
Here is the python code:
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Load the image
image_path = 'your path to image'
image = cv2.imread(image_path)
# Convert to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply Gaussian blur to reduce noise
blurred_image = cv2.GaussianBlur(gray_image, (5, 5), 0)
# Apply Canny edge detection
edges = cv2.Canny(blurred_image, threshold1=50, threshold2=150)
edges_colored = np.zeros_like(image)
edges_colored[:, :, 1] = edges # Set the red channel
overlay = cv2.addWeighted(image, 0.8, edges_colored, 1, 0)
# Display the overlaid image
plt.figure(figsize=(8, 6))
plt.imshow(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB))
plt.title('Original Image with Detected Edges in Red')
plt.axis('off')
plt.show()
And this is the image I want to detect edges for should follow the lines for the fringes. I have tried almost everything black and white increasing the contrast but it doesn't work. I have modified other image manually and for that it work and I don't know what can be the reason here is the working example:
What am I doing wrong that it doesn't work for the new image but for some reason works for the other. I have tried normalizing and played with threshold and brightness and contrast but didn't help. Thanks for the help!!
I am trying to detect the fringes/edges of the following image but it doesn't work
Here is the python code:
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Load the image
image_path = 'your path to image'
image = cv2.imread(image_path)
# Convert to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply Gaussian blur to reduce noise
blurred_image = cv2.GaussianBlur(gray_image, (5, 5), 0)
# Apply Canny edge detection
edges = cv2.Canny(blurred_image, threshold1=50, threshold2=150)
edges_colored = np.zeros_like(image)
edges_colored[:, :, 1] = edges # Set the red channel
overlay = cv2.addWeighted(image, 0.8, edges_colored, 1, 0)
# Display the overlaid image
plt.figure(figsize=(8, 6))
plt.imshow(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB))
plt.title('Original Image with Detected Edges in Red')
plt.axis('off')
plt.show()
And this is the image I want to detect edges for should follow the lines for the fringes. I have tried almost everything black and white increasing the contrast but it doesn't work. I have modified other image manually and for that it work and I don't know what can be the reason here is the working example:
What am I doing wrong that it doesn't work for the new image but for some reason works for the other. I have tried normalizing and played with threshold and brightness and contrast but didn't help. Thanks for the help!!
Share edited Feb 13 at 19:38 Mark Setchell 208k32 gold badges302 silver badges479 bronze badges asked Feb 13 at 14:39 wosker4yanwosker4yan 3231 gold badge4 silver badges14 bronze badges 8- Can you elaborate by attaching the images where it did not work, and how the output image looked like? – Naveed Ahmed Commented Feb 13 at 14:48
- The first image attached is the one that it didn't work. And I can't produce the same result anymore. But I can clearly see the fringes on the first image as well. – wosker4yan Commented Feb 13 at 14:50
- Did you try other popular and not so difficult to implement methods like Sobel and Prewitt? Or you are obliged to use this method? – Naveed Ahmed Commented Feb 13 at 14:54
- Nope I am not obliged I will have a look Sobel and Prewitt right now. – wosker4yan Commented Feb 13 at 14:54
- 1 Why do you want to detect edges? A sinusoidal pattern like this doesn't have true edges, of course, but it does have inflection points. But I suspect that you want to determine a frequency or something similar. Finding the ridges might be easier. You should also try frequency analysis. – Cris Luengo Commented Feb 13 at 16:04
1 Answer
Reset to default 0Try doing a color threshold with cv2.inRange() with lower=(170,0,0) and upper=(255,255,255) (instead of doing BGR2Gray and thresholding). Then convert to 8-bit gray (multiply by 255, then convert to uint8 using astype(np.uint8)). Then invert. Then do your Canny. Adjust the lower blue threshold value as desired to get more or less gap.
I did this quickly in ImageMagick, but can convert this to Python/OpenCV, if you have trouble.
magick image.png -alpha off -color-threshold "rgb(0,0,170)-rgb(255,255,255)" -negate -canny 0x1+10%+30% x.png
Is this close to what you want?
本文标签: pythonHow to detect edges of the following imageStack Overflow
版权声明:本文标题:python - How to detect edges of the following image - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741534339a2383943.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论