Last active
August 29, 2015 14:07
-
-
Save simplay/70d41412eac7333d0197 to your computer and use it in GitHub Desktop.
Brigthness center in image using a brightness threshold using image masking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% example determining brightness center from a given image A | |
% Args to provide: mask, image, threshold (perhaps). | |
% given a selection mask and image A like the following: | |
mask = | |
1 0 0 0 | |
1 1 0 0 | |
1 1 0 0 | |
0 1 1 1 | |
A = | |
43.851 118.591 246.394 89.275 | |
143.459 165.610 236.542 17.549 | |
235.809 255.000 255.000 236.195 | |
108.995 255.000 255.000 225.598 | |
[xMax, yMax] = size(A) | |
% assumption color values in [0,255] | |
% thus values above 250 can be supposed as being bright color spots. | |
brightness_threshold = 250 | |
% instead using conditional statements prepare another mask | |
belowBriThrMask = (A-(brightness_threshold+1)) >= 0.0 | |
% normalizationF is used in order to determine relative position. | |
maskedA = A.*(mask.*belowBriThrMask) | |
normalizationF = sum(maskedA(:)) | |
% (x,y) indices in image: | |
% all possible index pairs (x,y), i.e. pixel-coordinates | |
% are formed by collecting element-wise - in both matrices - their elements. | |
xIdx = repmat(1:xMax, yMax,1) | |
yIdx = repmat(1:yMax, xMax,1)' | |
maskedXIdx = maskedA.*xIdx | |
maskedYIdx = maskedA.*yIdx | |
birghtnessCenter = [sum(maskedXIdx(:)),sum(maskedYIdx(:))] / normalizationF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment