i have a picture of digits. i have croped that digits using blobanalysis then i resize that croped image to 20×20 and after place that 20×20 image into 28×28 image so that i can pedict that digit. but there is a problem when there is 1 in image and the box form around 1 is very small so when i resize that croped 1 it becom disorted. how can i fix this
clc;clear;BackgroundImage = imread('back.png');object = imread('11.png');subplot(3,3,1);imshow(object);title('Orignal Image');ga = rgb2gray(object);BW = im2bw(ga);subplot(3,3,2);imshow(BW)title('convert im2bw');gb = rgb2gray(BackgroundImage);foregroundDetector = vision.ForegroundDetector('InitialVariance',(30/255)^2);foreground = step(foregroundDetector, gb);foreground1 = step(foregroundDetector, ga);BlobAnalysis = vision.BlobAnalysis('MinimumBlobArea',100,'MaximumBlobArea',50000);[area,centroid,bbox] = step(BlobAnalysis,foreground1);Ishape = insertShape(object,'rectangle',bbox,'Color', 'green','Linewidth',6);subplot(3,3,3);imshow(Ishape);no_of_digits = size(bbox,1);pred = zeros(1,no_of_digits);for k = 1:no_of_digits im_k = imcrop(ga,bbox(k,:)); im_k = imresize(im_k,[20,20]); white = 255 * ones(28, 28, 'uint8'); white(5:24,5:24) = im_k; final_image = white; subplot(3,3,k+3) imshow(final_image) pred(k) = pred_number1(final_image); imshow(final_image)end
Thanks 🙂
Best Answer