Clear Filters
Clear Filters

How can I detect regions in image using x,y coordinates?

3 views (last 30 days)
I am a newbie in Image Processing using Matlab. have been successful in doing Marked Circle recognition using Template Matching.This is the code I used:
function[res] = findtemplate(image, template, th, showtemp)
im = rgb2gray(imread(image));
temp = rgb2gray(imread(template));
close all
out = normxcorr2(temp, im);
[m, n] = size(temp);
out = out(m+1: end, n+1: end);
bw = out > th;
r = regionprops(bwlabel(bw));
if nargin > 3
im(1:m, 1:n) = temp;
end
res = r;
clf
imshow(im, [])
hold on
for i=1:length(r)
rectangle('position', [r(i).Centroid(1), r(i).Centroid(2), m, n], 'EdgeColor','r','LineWidth',2);
end
Output image looks like this:
And now I must detect that numbers using x,y coordinates.It would be helpful if someone explains it better since I am a newbie.Thanks in advance!
  1 Comment
AminaOsmanova
AminaOsmanova on 22 Feb 2017
Edited: AminaOsmanova on 22 Feb 2017
I already detected for example that student chose 'A' in question '1' in attached image,now i need to detect each question number(ex:from 1-105) thanks in advance

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 25 Feb 2017
I may still work on the demo, but try what I have so far using the attached m-file and the attached PNG image file (slightly cropped from the one you uploaded).

More Answers (1)

Image Analyst
Image Analyst on 23 Feb 2017
Edited: Image Analyst on 23 Feb 2017
I don't understand how or why you found that the filled-in circle for question #1 was A instead of B, but whatever....
For the rest of the circles, simply use your template (list of circle locations) to determine which circle on the row has the most non-white and non-red pixels on it. I.e. find the most gray, black, or blue pixels. If none have enough, then that question went unanswered. Just do what you did to find the first question for all the other questions. What's the difficulty?
[EDIT] Ooooohhhh. I just took a look at your code. That's not good. Bad idea. I know you might think it's a good idea (like many other beginners), but it's not. And if someone says to try findcircles() or hough(), don't pay attention to them either. It's another idea that some beginners might suggest but it is ridiculous. What you need to do is to have a list of rows and columns where the circles are, then simply look in those regions. This is a much, much simpler approach. Simply use the FAQ http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F to build a binary mask at each circle centroid location, and check the darkness by asking regionprops for MeanIntensity of the blue channel of the image.
  3 Comments
Image Analyst
Image Analyst on 25 Feb 2017
This is a commonly enough asked question that I'm working on a demo. I'll post something tomorrow.

Sign in to comment.

Categories

Find more on Image Processing Toolbox 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!