【问题标题】:How can I add features from different images and merge them into a final imageHow can I add features from different images and merge them into a final image
【发布时间】:2022-12-02 10:22:32
【问题描述】:

I have some images, each of which may contain one or more blobs, I know how to load the image and convert it to binary but I want to be able to add all found blobs from any amount of images and paste them into a final image (which will start out blank).

I don't know if opencv or pillow is better for this as I have very little experience or knowledge in feature extraction.

Code

import cv2

# use cv2 imread method to load image
img1 = cv2.imread("im1.jpg")
img2 = cv2.imread("im2.jpg")

# make bw image
im1_gray = cv2.imread("im1.jpg", cv2.IMREAD_GRAYSCALE)
im2_gray = cv2.imread("im2.jpg", cv2.IMREAD_GRAYSCALE)

# get threshold and binary image
(thresh, im_bw1) = cv2.threshold(im1_gray, 128, 255,
                                 cv2.THRESH_BINARY | cv2.THRESH_OTSU)

# save binary image 1
im_out1 = "bw_image_1"
ext = ".png"
im_name = im_out1 + "_" + str(thresh) + ext
cv2.imwrite(im_name, im_bw1)

# get threshold and binary image
(thresh, im_bw2) = cv2.threshold(im1_gray, 128, 255,
                                 cv2.THRESH_BINARY | cv2.THRESH_OTSU)

# save binary image 2
im_out2 = "bw_image_2"
ext = ".png"
im_name = im_out2 + "_" + str(thresh) + ext
cv2.imwrite(im_name, im_bw2)

Images

Desired output

I don't know how to do this manually, but the output for this would be either a white or grey background with two black blobs in it.

If either of these images had two blobs in it and the other image had three blobs the output image would have five blobs, with positions equal to that of their position in the original image(s), it does not matter if they overlap.

【问题讨论】:

  • Your question is not clear. Please try to give some more examples of input image and the outputs you want. I guess you want to crop out the black circles and paste them in another blank image.
  • Yes I want to crop out the blobs and paste all of them (for the whole image set) into a single image.
  • I don't know how to do this manually, but the output for this would be either a white or grey background with two black blobs in it.

标签: python image opencv


【解决方案1】:

This has been asked before on opencv c++, there should be the same function on python3, hconcat, placing two images side by side, opencv 2.3, c++

【讨论】:

    猜你喜欢
    • 2022-12-02
    • 2022-11-20
    • 2022-12-27
    • 2022-12-27
    • 2022-12-28
    • 2022-12-02
    • 2022-12-28
    • 2022-12-02
    • 2022-12-02
    相关资源
    最近更新 更多