How to draw a line that separate white pixels in percentages on a image
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to draw a vertcal line that can seperate white pixels in the image with the percentages as shown in the figure. I can't use regionprops since each white pixel information is important to me. I have attached binary image for reference. Thanks in advance.
0 Kommentare
Akzeptierte Antwort
DGM
am 9 Feb. 2022
Bearbeitet: DGM
am 9 Feb. 2022
Something like this should work:
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/888330/binaryimage1.jpg');
A = rgb2gray(A)>128;
lhsfrac = 0.95;
% find the transition point
Aprof = cumsum(sum(A,1));
breakpoint = find(Aprof >= Aprof(end)*lhsfrac,1,'first')
% plot the profile for sake of clarity
figure(1)
plot(Aprof); hold on
plot([0 numel(Aprof)],[1 1]*Aprof(end)*lhsfrac,':')
% show the image and plot a line over it
figure(2)
imshow(A); hold on
plot([1 1]*breakpoint,[0 size(A,1)])
% if you want to actually embed the line in the image
figure(3)
B = im2uint8(repmat(A,[1 1 3]));
B(:,breakpoint,:) = repmat(permute([1 0.2 0.8]*255,[1 3 2]),[size(A,1) 1 1]);
imshow(B);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!