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
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.
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.
– danieltakeshi
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?
– Tecnologia da Net
@danieltakeshi I want to sort the colors of these spots.
– Tecnologia da Net