resize each symbol in binary image based off specific dimensions then put the image back together again?

2 views (last 30 days)
im trying to resize each symbol then put them back together again in the same image with changed dimensions. i can resize one symbol but im unsure how to do the same for all of them and put it together again
if true
i = imread('sample2.jpg');
b = rgb2gray(i);%grayscale
figure, imshow(b),title("grayscale")
c = 255-b %white
I = imbinarize(c);
cc = bwconncomp(I)%find connected componets
props = regionprops(cc, 'Image');
symbol = props.Image;
smaller_extracted = imresize(symbol, [64 64])
imshow(smaller_extracted);
end
in the image provided i would only be able to resize 1. im not sure how to access the second symbol 2 and put it back together.

Answers (2)

Image Analyst
Image Analyst on 12 Nov 2018
Threshold the image and crop each blob out. See my Image Processing Tutorial for code. https://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc
Then for each cropped image, resize it to the same number of rows and stitch together like this:
wideImage = [leftImage, rightImage];
  1 Comment
Imagestudent
Imagestudent on 15 Nov 2018
Edited: Imagestudent on 15 Nov 2018
i = imread('sample2.jpg');
b = rgb2gray(i);%grayscale
figure, imshow(b),title("grayscale")
c = 255-b %white
I = imbinarize(c);
cc = bwconncomp(I)%find connected componets
props = regionprops(cc, 'Image');
for x = 1: 7
symbol = props(x).Image;
smaller_extracted = imresize(symbol, [64 64])
imshow(smaller_extracted);
end
i can get each resized blob but im not sure how to put them back together with
wideImage = [leftImage, rightImage]; whats left and right image in this case? im using the image sample2

Sign in to comment.


Image Analyst
Image Analyst on 16 Nov 2018
Edited: Image Analyst on 16 Nov 2018
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
rgbImage = imread('sample2.jpg');
grayImage = rgb2gray(rgbImage); % Convert to grayscale
subplot(4, 3, 1);
imshow(grayImage);
title('Gray Scale Image', 'FontSize', fontSize);
binaryImage = ~imbinarize(grayImage);
subplot(4, 3, 2);
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize);
cc = bwconncomp(binaryImage)%find connected componets
props = regionprops(cc, 'Image');
finalImage = [];
for k = 1 : length(props)
symbol = props(k).Image;
smaller_extracted = imresize(symbol, [64 64]);
subplot(4, 3, k+2);
imshow(smaller_extracted);
axis('on', 'image');
drawnow;
finalImage = [finalImage, smaller_extracted];
end
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
subplot(4, 3, 10:12);
imshow(finalImage);
axis('on', 'image');
title('Final Stitched Image', 'FontSize', fontSize);
  2 Comments
Image Analyst
Image Analyst on 18 Nov 2018
It's a perfect rectangular block so it completely fills the 64x64 image 100%. What were you expecting?
If you want a "margin" around the numbers instead of using the exact bounding box, resize them to 62 by 62 and use padarray() to add a one pixel layer around the outer edge.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!