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 visualización (últimos 30 días)
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)

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de En. de 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);
Warning: One or more ties for n-th place occurred when selecting objects. Some objects were not selected.
figure,imshow(BW2)
BW4 = bwareafilt(BW,1,'smallest');
Warning: One or more ties for n-th place occurred when selecting objects. Some objects were not selected.
figure, imshow(BW4)
BW3 = repmat(BW, 1, 1, 3);
BW3(:,:,1) = BW & ~ BW4;
BW3 = im2uint8(BW3);
figure, imshow(BW3)
  4 comentarios
DGM
DGM el 21 de Oct. de 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)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by