After some searching, I did not find a solution to the following problem, which in my thinking should have some very easy/efficient solution.
I'm looking at a list of images (faces), that I want to conform via FindFaces
faces =
ConformImages[HistogramTransform @ ImageTrim[#, FindFaces[#][1]]]& /@ images,
ColorSpace -> "Grayscale"]
So far this works like a charm and can also be found here: $\quad \quad $https://reference.wolfram.com/language/example/GenderClassification.html
PROBLEM: The problem is that FindFaces
is unable to detect some images and thus creates an error. This error is carried forward into the results list.
GOAL: Essentially I want to simply drop the error from the list. I also need to extract the position of those images to drop corresponding values from a secondary variable.
As the initial problem is not reproducible, here my idea as a very simplified example:
results = Table[1/i, {i, -5, 5}]
results[[6]]
posDrop = 6
resultsClean = Delete[results, posDrop]
The 6th value of the list returns the error message "ComplexInfinity". To somehow extract the position (i.e. 6) would suffice, but I'm looking for a solution that does not require me to know the specific error message or, for the image problem, finding non-numeric entries.
DeleteCases[]
? $\endgroup$Position
. $\endgroup$DeleteCases[list, _DirectedInfinity]
will strip out any infinite results inlist
, since the pattern in the second argument captures how infinities are represented in Mathematica. $\endgroup$Cases[]
andDeleteCases[]
are complementary functions when given the same list and pattern. $\endgroup$