text.how can I find the largest and smallest size letters in a png image and display them in a different color in the image (without deleting other letters)?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
betty
am 6 Jan. 2022
Kommentiert: DGM
am 21 Okt. 2022
how can I find the largest and smallest size letters in the image below and display them in a different color in the image (without deleting other letters)? With the following code, I find the uppercase letter and the lowercase letter, but the other letters are deleted and I can't show them in a different color
BW = imread('text.png');
BW2 = bwpropfilt(BW,'perimeter',1);
figure,imshow(BW2)
BW4=bwareafilt(BW,1,'smallest');
figure, imshow(BW4)
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 6 Jan. 2022
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/855240/image.jpeg';
img = imread(filename);
if ndims(img) > 2; gray = rgb2gray(img); else gray = img; end
BW = imbinarize(gray);
BW2 = bwpropfilt(BW,'perimeter',1);
figure,imshow(BW2)
BW4 = bwareafilt(BW,1,'smallest');
figure, imshow(BW4)
BW3 = repmat(BW, 1, 1, 3);
BW3(:,:,1) = BW & ~ BW4;
BW3 = im2uint8(BW3);
figure, imshow(BW3)
4 Kommentare
DGM
am 21 Okt. 2022
Just for fun, let's say we wanted to color code all the letters by their size (area).
inpict = imread('text.png'); % a binarized image
N = 256; % length of color table
CT0 = parula(N); % a color table
% get blob areas
S = regionprops(inpict,'area');
% rescale areas to create indices into color table
area = vertcat(S.Area);
ctidx = round(normalize(area,'range')*(N-1) + 1);
% create augmented CT
CT = [0 0 0; CT0(ctidx,:)];
% get label image, convert to RGB
L = bwlabel(inpict);
outpict = ind2rgb(L+1,CT); % FP-class indexed images are offset by 1
% display it
imshow(outpict)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Convert Image Type 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!