I have a matrix named original
and the respective plot is shown in the image below.
I would like to however get the center portion of the image in the form of respective rows into another variable as highlighted approximately in the next figure.
I looked up to find the center and got to know of the method of using centroid
in regionprops
. For example like the code sample below.
s = regionprops(original,'centroid');
centroids = cat(1, s.Centroid);
plot(centroids(:,1),centroids(:,2), 'b*')
This method of using centroid
did not help me to obtain the entire central rows. Is there any alternative way of doing this?
One way to compute the average non-zero index in each column would be to directly compute it.
Edit: It's not clear what is meant by noise, but if I interpret this as you want to only consider the widest region per column then we can find the average of this region as follows.
avg = zeros(1,size(original,2));
for c = 1:size(original,2)
% find largest contiguous region in the column
sig = original(:,c);
der = diff([false; sig; false]);
upedge = find(der == 1);
downedge = find(der == -1);
[~,region_idx] = max(downedge-upedge);
first = upedge(region_idx);
last = downedge(region_idx)-1;
% get the average index in the region
avg(c) = (last + first) / 2;
end
% plot results
hold off;
imagesc(original); hold on;
plot(1:size(original,2), avg, '-r', 'LineWidth', 2);
set(gca, 'YDir', 'normal');
axis([1, size(original,2), 1, 250]);
Which, results in the following figure