Effacer les filtres
Effacer les filtres

how to compare answers ,which student chose it in answer sheet with answer key

8 vues (au cours des 30 derniers jours)
AminaOsmanova
AminaOsmanova le 11 Fév 2017
Réponse apportée : DGM le 17 Avr 2024 à 9:32

Réponses (1)

DGM
DGM le 17 Avr 2024 à 9:32
Since there are no requirements at all, I choose to interpret the task in whatever way is dictated by the sum of whimsy and laziness over the course of writing this example.
Start with a template image and a mask. Don't have one? Make one. For this example, I'm going to be extra lazy and make sure that the columns of cells in the image (specifically in the mask) are grid-aligned exactly. This ensures that they will be labeled in the expected order (top-bottom, left-right). Are there more robust ways to ensure their order? Yes.
Take the scanned test image and perform whatever registration and transformation is required to bring it into spatial correspondence with the template image. There are reasons that documents designed to be machine-readable have fiducials and other markings on them. You might use them.
I'm just going to work off of the average difference between gray levels within each cell. Inadequate marks are inadequate. Instead of diving below the noise floor to divine intent, I'm going to simply use a naive threshold to discern which marks are sufficient. After all, that entirely suits my requirements.
% you have standard template images
ref = imread('scancard_blank.jpg');
mask = imread('maskdots.png');
% and you take your scanned image and somehow
% register it so that it corresponds
inpict = imread('scancard.jpg');
% calculate the error between the two images
err = abs(im2double(inpict) - im2double(ref));
err = im2gray(err);
% get the error magnitude in all the mask regions
S = regionprops(mask,err,'meanintensity');
allerr = reshape([S.MeanIntensity],15,5,7);
allerr = reshape(permute(allerr,[1 3 2]),[],5);
% reduce it to logical data describing marked cells
markedcells = allerr > 0.15; % pick some threshold
% visualize the selection
outpict = markuserselection(inpict,mask,markedcells);
imshow(outpict,'border','tight')
Of course, it's not typical that a form is used where there are multiple answers per question. I'm going to assume that there is only one valid answer per question, rejecting all cases where there are multiple detected marks per question.
% reject invalid selections
isunique = sum(markedcells,2) == 1;
markedcells = markedcells & isunique;
% visualize the selection
outpict = markuserselection(inpict,mask,markedcells);
imshow(outpict,'border','tight')
function outpict = markuserselection(inpict,mask,userselection)
% this is just a convenience tool to visualize which marks are accepted
% reorient the data to match the segmentation order
userselection = reshape(userselection,15,7,5);
userselection = permute(userselection,[1 3 2]);
% create a mask describing the selected circles
L = bwlabel(mask);
selectedblobs = any(L == permute(find(userselection),[3 2 1]),3);
selectedblobs = imdilate(selectedblobs,ones(5)) & ~selectedblobs;
% create a composite image
outpict = imoverlay(im2gray(inpict),selectedblobs,[1 1 0]);
end
Now you have a 105x5 logical array that describes only the valid marks. Assuming you have a similar logical array describing the correct answers, then you can check which answers were correctly marked.
% check the answers against the hypothetical key
answeriscorrect = any(markedcells & answerkey,2);
Want to do the mark discrimination differently? Go ahead. You have a 105x5 array of mean error values to work with. You can process them however you choose.

Community Treasure Hunt

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

Start Hunting!

Translated by