How to sort and get the coordinates of specific blobs

4 views (last 30 days)
I've already attached some image to give you an idea of what i'm trying to do. You see, this is a scanned picture. I'm kinda new when it comes to this kind of stuff, so i don't know much yet
i put four blue dots on the 4 corners of the paper so i could use them as control points(im trying to align this image with another one using the cp2tform function). I've tried to extract the coordinates of the blobs manually through MS paint and it worked. Theres no problem with the control points for the base exam paper since it will be the same for each computation, while for the moving image, it would be different for each scanned image. Please help me find a way to sort hose four blobs from the rest and extract their coordinates. Thanks guys.

Accepted Answer

Image Analyst
Image Analyst on 19 Apr 2014
First I'd straighten the image by finding the centerline, getting it's angle (orientation from regionprops()) and them calling imrotate.
Then take the red channel, which will give the most contrast, then invert the image (to make lines white and background dark). To find the centerline, first call imdilate (to make sure it's connected and has no breaks or gap), then threshold, label with bwlabel(), call
measurements = regionprops(labeledImage, 'MajorAxisLength', 'Orientation');
asking for MajorAxisLength, and look for the blob with the largest MajorAxisLength and Orientation. Then use imrotate, passing in the orientation, to straighten the image.
straightenedImage = imrotate(grayImage, orientationAngle);
I wouldn't bother with cp2tform. That's just more complicated than it needs to be.
See my Image Segmentation Tutorial if you need an example: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
What might be better than to get all 50 centroids in one shot would be to get a sub image for each question. This would involve straightening the image (described above) then getting the vertical profile by calling
verticalProfile = mean(grayImage, 2);
and by thresholding that profile identifying where each line starts and stops. Then have a loop where you extract the rows for the question, threshold, call regionprops. Do that for both the left half of the band of rows you extracted, and for the right half.
It doesn't look too hard - I could probably do it within an hour. I mean, to give the letter selected for each question. Come back with a good attempt at the coding if you have trouble.
  8 Comments
Teddy valladolid
Teddy valladolid on 20 Apr 2014
thanks a lot! it worked! now there's just one more thing, how can i transform/make the rotated image in such a way that itll follow the xdata and ydata of my Base image. their correction angle is more or less the same now, but the boxes are off by (x,y) i just want it to fit with the base image when use imshowpair or when i multiply the images when they are in the BW/logial format.
Image Analyst
Image Analyst on 20 Apr 2014
I've read this 4 times and I don't know what you're talking about. What are xdata and ydata? What boxes? Why are you using imshowpair()? Why are you multiplying images? Like I said, simply look in the areas where you'll find the boxed and find which one, if any, are filled. You know the length of the line and the two endpoint locations so you know the rows where the questions start and stop and know how many questions are in between so just look in those bands like I explained earlier.

Sign in to comment.

More Answers (1)

Teddy valladolid
Teddy valladolid on 19 Apr 2014
Yup, I've tried your codes above and the result was pretty much the same. It rotated the whole image by an angle and its kinda diffrent from what i have in mind. I just cant really explain it well with words so i figured out that id just show you what i did. you can see that i've put the control points manually. I used the cpselect tool for that, and now im trying to make a code which will provide me the coordinates of the Control Point Markers in the Student Sheet image to use it as the input_points for my cp2tform since i've already assigned fixed values for my base_points. I really appreciate that you are helping me mr. image analyst.
>> i=imread('base.jpg');
>> i2=imread('exam.jpg');
>> t=cp2tform([500 169;477 771;35 77;10 754],[483 158;481 751;18 83;12 758],'affine');
>> info = imfinfo('base.jpg');
>> registered = imtransform(i2,t,'Xdata',[1 info.Width], 'Ydata',[1 info.Height]);
>> figure,imshowpair(i,registered)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!