How to remove area of interest from the background of an image?

Asked

Viewed 1,206 times

4

I am starting to work with image processing in pattern recognition, and I need to do pre-processing of the images I will use. First, I need to highlight the region of interest from the background of the image, can anyone tell me what is the best technique for this? I’m using opencv plus python for this procedure.

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

Second, I need to identify the colors of this region of interest and plot a 3d chart.

  • 1

    I don’t know what kind of analysis you want, it can be a simple color histogram. Or I was reading recently: this article, using the EMD Two-dimensional for color photos.

  • Okay, I’ll give you a read. as for the removal of the background and highlight only the area of interest, you have some technical tip?

  • @danieltakeshi I want to sort the colors of these spots.

1 answer

6


To extract you can use the Grab Cut opencv

A example can be seen in the tutorial "Interactive Foreground Extraction using Grabcut Algorithm"

Code

Using the example code:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('C:\\Users\\Desktop\\teste\\FHB9o.jpg')

mask = np.zeros(img.shape[:2],np.uint8)

bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)

rect = (10,10,45,45)
cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT)

mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
img = img*mask2[:,:,np.newaxis]
cv2.imshow('Imagem', img)
cv2.waitKey(0)
cv2.imwrite('C:\\Users\\Desktop\\teste\\resultado.jpg', img)
plt.imshow(img),plt.colorbar(),plt.show()

Upshot

Resultado

Observing

In this case the rectangular ROI (Region of Interest) is fixed. If the images have variation in the location of the object that needs to be extracted, a dynamic ROI needs to be created, where the contours will be the points that will determine the coordinates of the dynamic ROI.

  • it worked, obgdo. Can you help me on this one? https://stackoverflow.com/questions/52707256/how-to-remove-hair-noise-from-skin-images-using-opencv

  • 1

    I think you can do a Canny contour test, then filter the objects through the contour area. Hoping the contours are smaller than the object you want to detect.

  • @Carlosdiego This is a Stack Overflow site in English, please speak in Portuguese. And if you have a question in Javascript, please ask a new question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.