How to delete an item in a matrix by comparing the correlation with the next neighbor in a same column
1 view (last 30 days)
Dear all, I have faced a confusing matrix problem when I am learning image processing. Like if I have a matrix A(3*45), I would like to compare each row(1*45), if the row has a value, then get its position. Furthermore, if the following number doesn't have a value for more than 5 following steps, then stop counting the rest of the value. step Finally get the maximum (x1)and the minimum(x2) position in that row. Finally, put the answer into a matrix Q(X2, X1).Thank you !!
Here is my code (it's not correct):
for j = 1:size(A)
Jan on 13 Dec 2021
With bold guessing:
for j = 1:size(A, 1) % Not size(A), because this replies a vector!
line = A(j, :);
blockOfZeros = strfind(line(2:end), zeros(1, 5)) + 1;
line(blockOfZeros(1):end) = 0;
x1 = find(line, 1, 'last');
x2 = find(line, 1, 'first');
% ??? Q(x1,x2)
% How do you want to store x1 and x2 if no matching elements
% are found?
Image Analyst on 13 Dec 2021
Tell us what you REALLY want. Like, what are you going to do once you have the starting and ending columns at each row?
Chances are you can go line by line and use image processing functions like bwareaopen() or bwareafilt() or regionprops() to get certain regions. But I really need to know why you want these values.
And I also need to know why you want to stop counting if there are more than 5 0's in a row.
And Q can't be a rectangular array because it might be possible for you to have several runs, not exactly 2. Or do you want there to be 2? And what if there are more than 2? Just take the longest 2? If so, why?
Again we need the context for all this.