Image processing and sub-array summation

조회 수: 6 (최근 30일)
Julius
Julius 2019년 9월 17일
답변: Julius 2019년 9월 18일
I have a problem that seems fairly straight forward but I am having trouble pulling it off in an efficient (no for loops) manner. For a bit of background, I am processing an image of an array of similar objects and want to flag locations where an object is missing. I can assume that the pitch in x and y is the same and that each object (if present) generates roughly the same intensity in my image. The image will consist of around 10k objects and perhaps 100's of thousands of objects in the future, hence the need for efficiency.
The algorithm I had in mind would work something like this...
1) Partition image array into "sub-arrays" using the indicies of two vectors which are defined by the pitch of the object array on the image plane.
2) Compare "sub-array" sums to a given threshold
3) Generate array of 1's and 0's corresponding to precense or lack of object.
For example, assuming my pitch in x and y is 2,
Raw Data:
[ 1 1 2 1 1 1 2 2;
1 0 1 1 2 1 2 1;
0 0 1 2 2 1 0 0;
0 1 1 0 2 1 0 0;
2 1 2 2 2 1 1 1;
1 0 1 2 2 1 1 1]
Summation of Sub-arrays:
[ 3 5 5 7;
1 4 6 0;
4 7 6 4]
Threshold = 2
Output:
[1 1 1 1;
0 1 1 0;
1 1 1 1]
Anyway, I'm stuck at step one and was hoping someone might point me in the right direction.
Thanks in advance,
Julius
  댓글 수: 1
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 9월 17일
Partition image array into "sub-arrays" using the indicies of two vectors
How, Can you show us one example?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2019년 9월 18일
Try conv2():
bigMatrix = [ 1 1 2 1 1 1 2 2;
1 0 1 1 2 1 2 1;
0 0 1 2 2 1 0 0;
0 1 1 0 2 1 0 0;
2 1 2 2 2 1 1 1;
1 0 1 2 2 1 1 1]
% Compute moving sums by using highly optimized conv2() function.
p = 2; % "Pitch"
kernel = ones(p);
out = conv2(bigMatrix, kernel, 'same')
% Sub sample to get just the elments we want.
out = out(1 : p : end, 1 : p : end)
% Now do the thresholding.
threshold = 2;
out = out > threshold
You'll see in the command window the different output from each step:
out =
3 4 5 5 5 6 7 3
1 2 5 7 6 4 3 1
1 3 4 6 6 2 0 0
4 5 5 6 6 3 2 1
4 4 7 8 6 4 4 2
1 1 3 4 3 2 2 1
out =
3 5 5 7
1 4 6 0
4 7 6 4
out =
3×4 logical array
1 1 1 1
0 1 1 0
1 1 1 1

추가 답변 (2개)

Matt J
Matt J 2019년 9월 17일
편집: Matt J 2019년 9월 17일
You can use sepblockfun from the File Exchange
Output = sepblockfun(RawData,[2,2],'sum')>threshold

Julius
Julius 2019년 9월 18일
Brilliant, this is exactly what I needed. Thank you Matt and "Image Analyst" for the suggestions!
Cheers,
Julius

제품

Community Treasure Hunt

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

Start Hunting!

Translated by