Hola!
Os comento una duda que tengo con mi código en Python, por si alguno pudiera ayudarme.
Tengo una imagen de un ala de mosca tal que así:
y quiero cuantificar cuánto del área del ala está ocupado por la mancha, así que he escrito esto:
# Independent estimations of the contours - the whole wing and the wing spot
# Then, identification of the areas corresponding to the whole wing and the wing spot
# Finally, the areas of each contours are estimated and the ratio is inferred
# Packages loading. Remember the install needs to be done from the command line
import cv2
import numpy as np;
# Import of the image
im = cv2.imread('.\\M1D_Bar.jpg')
# Image blurring
blurred = cv2.pyrMeanShiftFiltering(im, 31,91)
# Blurred image turned to gray scale
gray = cv2.cvtColor(blurred, cv2.COLOR_BGR2GRAY)
##### Here's where the part corresponding to the WHOLE WING starts
# Colour threshold is applied, so the background of the wing is separated
ret , thresh = cv2.threshold(gray, 0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# Estimation of all the contours (wing vs background and others!)
_ , cont, _ = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
# Representation of the 6th contour (wing vs background)
cv2.drawContours(im, cont, 6, (255,255,0),6)
cv2.namedWindow('Wing contour', cv2.WINDOW_NORMAL)
cv2.imshow('Wing contour', im)
##### Here there's the part belonging to the spot
# A hardcore colour threshold is applied, so the spot is identified
retval, threshold = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
# Estimation of all the contours (spot vs rest and others!)
_ , contours, _ = cv2.findContours(threshold, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
# Representation of the 105th contour (spot vs rest)
cv2.drawContours(im, contours, 105, (255,255,0),6)
cv2.namedWindow('Spot area', cv2.WINDOW_NORMAL)
cv2.imshow('Spot area', im)
###### Estimation of the ratio spot area / wing area
ratio = cv2.contourArea(contours[105]) / cv2.contourArea(cont[6])
Creo que el trabajo me lo hace, pero no entiendo por qué al intentar representar sólo el área de la mancha también me representa el contorno del ala y me da miedo, porque me preocupa entonces que al estimar el ratio mancha/ala también esté cogiendo áreas que no son. ¿Alguna idea/observación?