How to check a pixel is within a range?
5 views (last 30 days)
Show older comments
I have a image matrix DM (which pixel values are in range 0 to 12, i attached the values),
i want to create a matrix Aux from DM as follows
Aux pixels are set to the gray-level 255 before performing the process for any given direction. The value 255,white, is chosen since it identifies the gray-level of pixels certainly belonging to the background. During the ith inspection, only and all the pixels of DM with value in the range [i -2, i + 2] are copied onto Aux, where are assigned value 0. In fact, the pixels currently copied onto Aux were (tentatively) interpreted as vessel pixels during the construction of DM, and it is then reasonable to assign to themthe gray-level 0, black,which is definitely a value for foreground pixels.
Condition checking is we remark that for any i (i = 1,2, … , 12), i + 1and i + 2 are computed modulo 12; as for i -1and i - 2, if these values result to be ≤0 they are increased by 12, so as to avoid copying in Aux pixels with i = 0, which does not correspond to a valid direction for foreground pixels.
Can anyone help me to understand it ?
2 Comments
Walter Roberson
on 27 Jan 2016
When i = 10, then (i+2) mod 12 = 0, so do we need to avoid coying the 0, and we would copy 9, 10, 11? Or we would copy 9, 10, 11, 12?
When i = 11, then (i+2) mod 12 = 1, so the [i-2, i+2] mod 12 would be [9, 1] so does that mean that we should be copying 1, 2, 3, 4, 5, 6, 7, 8, 9, or does it mean we should be copying 9, 10, 11, 12, and 1, or 9, 10, 11, and 1 ?
Accepted Answer
Guillaume
on 27 Jan 2016
Edited: Guillaume
on 27 Jan 2016
If I understood correctly, this is the algorithm:
DM = dlmread('Dm.txt');
for level = 0 : 12
Aux = ~ismember(DM, mod(level-2:level+2, 13)) * 255;
%do something with Aux
end
edit: in your intro you say the range is [0-12], which would mean a modulo 13 operation.
edit-edit: Or maybe the 0 value is to be ignored, in which case:
DM = dlmread('Dm.txt');
for level = 0 : 11 %offset by one later
Aux = ~ismember(DM, mod(level-2:level+2, 12) + 1) * 255;
%do something with Aux
end
3 Comments
Walter Roberson
on 27 Jan 2016
In the expression ~ismember(A,B)*255 the ~ has higher priority than the * so the negation will be done first, giving a logical value. Then the logical value is multiplied by the double 255, the result of which will be class double, not class logical
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!