【问题标题】:Removing background from galaxy photos using Python使用 Python 从星系照片中删除背景
【发布时间】:2018-12-11 02:13:37
【问题描述】:

你能给我一些关于如何使用 Python 从星系图像中删除背景的提示吗?我想以某种方式检测星系并移除它之外的所有东西。

有没有机会用OpenCV 来做这件事?

所有图片如下所示:

【问题讨论】:

标签: python image-processing


【解决方案1】:

试试这个:

该方案的基本思路是,在执行threshold()后得到图像的轮廓,并检测出轮廓中最大的轮廓。

import cv2
image = cv2.imread("test.jpg", 1)
img = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU,img)
im2, contours, hier = cv2.findContours(img, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)

if len(contours) != 0:
    #find the biggest area
    c = max(contours, key = cv2.contourArea)
    x,y,w,h = cv2.boundingRect(c)
    cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),1)

cv2.imshow("Result", image)
cv2.waitKey(0)

输出:

【讨论】:

  • 简单有效。喜欢它!
猜你喜欢
  • 2021-11-29
  • 1970-01-01
  • 2021-02-06
  • 1970-01-01
  • 2023-01-03
  • 2020-12-11
  • 2011-01-11
  • 2013-05-09
  • 2012-12-19
相关资源
最近更新 更多