Find the median row of a binary column and replace the column with just the median row
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have some binary columns with ones and zeros. I would like to replace the places where there are multiple rows of ones with just one one in the median row index. I would like to do this for every column. For example:
1 0 1 1
1 0 1 1
1 1 1 0
0 1 1 0
0 1 0 0
becomes
0 0 0 1
1 0 1 0
0 0 0 0
0 1 0 0
0 0 0 0
The ones represent a curved y plot graph, that I would like to reduce down to a one pixel width (i.e. 1 y pixel per x value).
Thanks for any advice!
Chees
0 Commenti
Risposta accettata
Più risposte (3)
Image Analyst
il 27 Dic 2019
Yes of course. Not every stretch will be a horizontal or diagonal stretch.
0 Commenti
Andrei Bobrov
il 27 Dic 2019
I = imread('line.png');
bw = im2double(rgb2gray(I));
[i,j] = find(bw);
[n,g] = findgroups(j);
idx = floor(splitapply(@median,i,n));
[k,l] = size(bw);
out = zeros([k,l]);
out(sub2ind([k,l],idx,g)) = 1;
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!