How to check a pixel is within a range?

5 views (last 30 days)
Kalai S
Kalai S on 27 Jan 2016
Edited: Kalai S on 27 Jan 2016
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
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 ?
Kalai S
Kalai S on 27 Jan 2016
Sir, Thank you for your comment,Here we check the condition if the pixel in DM satisfies that condition we simply copy the value 0 in that pixel's position in Aux.
This is the process description given by the author.
Copying onto Aux not only pixels labeled i in DM,but also pixels with direction slightly different from the current direction di ,is done to favor the creation in Aux of connected components of pixels consisting of more than just a few sparse pixels, as it would be the case by considering only pixels with value i. In fact, the direction computed for sparse pixels or for small blobs of pixels is likely to be undetermined. In turn, working with bigger connected components that include the pixels for which we are planning to compute an updated direction greatly favors a correct computation. For the sake of completeness, we remark that for any i (i = 1,2, … , 12), i + 1and i + 2are 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 you provide me a sample code for this?

Sign in to comment.

Accepted Answer

Guillaume
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
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
Kalai S
Kalai S on 27 Jan 2016
Edited: Kalai S on 27 Jan 2016
Sir, You are correct. I did a mistake now i check it out. Thank you

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!