"I have a lot of these and the task is relatively simple.
I want to read the Image into Mathematica, then
extract a table of “0” and “1” values where the underlines on the data sheet are.
If each underline on the sheet is a cell, then the rule is:
Assign a “0” whereever the cell is blank (only has underline).
Assign a “1” if there is a mark that looks like a “1” in the cell.
Export the table to a data file or spreadsheet.
does anyone have experience with this type of task?"
Thanks
Given an image with some horizontal lines, how can tell which ones have a check over them?
First, let’s clean up the image. I like LocalAdaptiveBinarize for this. Finding the right coefficients for the function can done nicely with Manipulate
“Subtract” the checks from the original image to get an image with just the horizontal lines. I had to make the checks a bit bigger with dilation to make sure they were completely removed. ImageAdd was used because the previous result was a negative.
The last image called “lines” needs to be cleaned up a bit. This is done by removing some small components from the image, dilating the results to ensure that lines are connected and then thinning them out again.
We want to get the ends of each of those lines. Here’s how to get a simple bounding box for each from left to right, top to bottom:
boxes = ComponentMeasurements[%, "BoundingBox"]
Let’s average out the vertical components of each bounding box, since they’re supposed to be horizontal lines. This should give us a list of end points for each line:
A reasonable rule of thumb is that there’s a check if over 100 of the pixels are white:
checkedQ[img_] :=
Total@Flatten@ImageData[img] > 100 (*Threshold number of points*)
For your actual application, we’d either use the TextRecognize function or use the Classify function to make a digit recognizer. There are examples in the documentation on how to make a digit recognizer with the Classify function
Since the components are stored from left to right and top to bottom, we can easily visualize the results and compare with the original image:
We would probably want to build into this some checks to make sure that the image was being recognized properly. Maybe some extra code to handle such problems. For example, this wouldn’t have worked so easily if the horizontal lines weren’t as easy to find. Also we really aren’t using the fact that the lines are in a grid so there’s a lot we could possibly do for your application. If the images are all very consistent, we might not even have to go about finding where the checks/numbers should be for each image.
Dear Sean
Thank you so much. There are a few more issues to figure out but I will see what I can do.
You have helped us evaluate the largest database on the planet for Alzheimer’s.
Greatly appreciated.
Rod Shankle