Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata Extraction #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions metadataExtraction.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
function [age_crop, gender_crop, dominant_hand_crop, medium_crop, division_crop]= metadataExtraction(scanned_img, refPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function should take the registered image and metadata reference image as input, and output exact metadata information (gender = 'other'), not image crops.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function will be placed inside extract.m right after surfAlignGPU is performed. So you'll already have the registered image by then.


%% Load Scanned Image
img=imread(scanned_img);

%% OCR detect formID
roi = [2100 1 450 500];
dilate = 5;
ocrResults = ocrForm(img,roi,dilate,false); % display true
formID = ocrResults.Words{1};
formID = strip(formID);
if ~formID
formID= '8';
end

%% Load Template and Align
imRef = imread([refPath '\' 'form_' formID '.jpg']);
[rec,qual] = surfAlignGPU(imRef,img,true,false); % Nonrigid, disp
figure
imshowpair(imRef,rec);

%% Crop Scanned image for the metadata portion with suitable ROI
img=imcrop(rec,[115 185 1900-115 540-185]);
figure
imshow(img)

%% Crop metadataRef with Same ROI
metadata = imread([refPath '\metadataRef.png']);
metadata=imcrop(metadata,[115 185 1900-115 540-185]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where this is being used anymore. You should add something like this after the metadata imcrop.
metadata = imbinarize(rgb2gray(metadata));
img(~metadata) = 255; %% making everything other than the omr points of interest white
img = ~imbinarize(rgb2gray(img)); %% now you have only the omr blobs as white in the img

figure
imshow(metadata)

%% Centroids and Bounding Boxes for the OMR options
omr = ~imbinarize(rgb2gray(img));
omr = bwareaopen(omr,800);
CC = bwconncomp(omr);
L = labelmatrix(CC);
s = regionprops(CC,'Extent');
omr = ismember(L, find([s.Extent] >= .7));
s = regionprops(omr,'Centroid', 'BoundingBox');
centroids = cat(1, s.Centroid);
s = struct2cell(s);
s= s';
figure
imshow(omr)
hold(imgca,'on')
plot(imgca,centroids(:,1), centroids(:,2), 'r*')
hold(imgca,'off')

%% Extract
age= s{1,2};
gender= s{2,2};
dominant_hand= s{3,2};
medium= s{4,2};
division= s{5,2};

age_crop=imcrop(img,[age(1)+50 age(2) 105 45]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output of this function should be something like this:
age = '18-25'
gender = 'Other'
dom_hand = 'Left'

not image crops. This metadata will be directly appended to a csv file in the pipeline.

gender_crop=imcrop(img,[gender(1)+50 gender(2) 105 45]);
dominant_hand_crop=imcrop(img,[dominant_hand(1)+50 dominant_hand(2) 105 45]);
medium_crop=imcrop(img,[medium(1)+50 medium(2) 105 45]);
division_crop=imcrop(img,[division(1)+50 division(2) 105 45]);

figure
imshow(age_crop)
figure
imshow(gender_crop)
figure
imshow(dominant_hand_crop)
figure
imshow(medium_crop)
figure
imshow(division_crop)