image inpainting

10 visualizzazioni (ultimi 30 giorni)
uday modha
uday modha il 26 Gen 2012
Commentato: Josephine il 4 Apr 2014
I am student of M.E.(I.T.). i have a research topic is "image inpainting(text removal)". my task is to remove superimpoed text from images. my first task is to extract text from images. i have succussfully extract text from the images. so my problem is how can i remove that text from images. is there any method??? can u please suggest me???
thanks and regards,
uday modha M.E.(I.T)
  9 Commenti
uday modha
uday modha il 27 Gen 2012
sir did you check the code??? what is my next step??? is there any new algorithms???
Josephine
Josephine il 4 Apr 2014
Mr Uday, What is the text to be entered?

Accedi per commentare.

Risposte (3)

Sean de Wolski
Sean de Wolski il 26 Gen 2012

Image Analyst
Image Analyst il 26 Gen 2012
I think roifill() would suit your needs. It's part of the Image Processing Toolbox. Or check this link: <http://spie.org/app/program/index.cfm?event_id=956859&export_id=x16280&ID=x16223&redir=x16223.xml&search_text=inpainting&type=2&programDays=0&x=29&y=10> for 8 talks this week at Electronic Imaging symposium on the subject.

Josephine
Josephine il 4 Apr 2014
Is this code valid? does this give a promising result?
  3 Commenti
Josephine
Josephine il 4 Apr 2014
The code above for removing text using inpainting. I tried using the image which was used in this code itself, but there is a point where it is asking to enter the text. So what should be the text.
Josephine
Josephine il 4 Apr 2014
the code is
loadName='123.jpg'; I_in = imread(loadName);
% Input should be a 2D grayscale level image or 3D RGB image dim_I = length(size(I_in)); if ((dim_I > 3) (dim_I < 2)) fprintf('\nError! Input Input should be a 2D grayscale level image or 3D RGB image\n'); return; end
% Initialization %I_out = uint8(zeros(size(I_in))); % init output
% Calculate Intensity Image Y % Y = 0.299R + 0.587G + 0.114B if (dim_I == 3) % if image is in RGB form %Y = 0.299*double(I_in(:,:,1)) + 0.587*double(I_in(:,:,2)) + 0.114*double(I_in(:,:,3)); Y = 0.299*I_in(:,:,1)+0.587*I_in(:,:,2)+0.114*I_in(:,:,3);
%Y = rgb2gray(I_in); uday=input('rgb'); else % if image is grayscale Y = I_in; end
dsRate = 3; % Downsampling N = downsample(Y,dsRate); N = N'; P = downsample(N,dsRate); Y1 = P'; clear N P; %edge0 = edge(Y1,'sobel',0.01); %edge0 = edge(Y1,'prewitt'); %edge0 = edge(Y1,'log'); %edge0 = edge(Y1,'roberts'); %edge0 = edge(Y1,'canny');
% Increase contrast Y1a = (double(Y1) / double(max(Y1(:)))).^1.5; Y1a = uint8(Y1a / max(Y1a(:)) * 255);
%Y1 = uint8(double(Y1) / double(max(Y1(:))) * 255);
% Y is blurred using open-closed / closed-open filters % (to reduced false edges and over-segmentation) SE = strel('arbitrary', ones(3,3)); %Y_bl = (imclose(imopen(Y1,SE),SE) + imopen(imclose(Y1,SE),SE))/2; Y_bl = (imclose(imopen(Y1a,SE),SE) + imopen(imclose(Y1a,SE),SE))/2;
% The Morphological gradient (MG) operator is applied to the blurred image % Y_bl resulting in an image e_s e_s = imdilate(Y_bl,SE) - imerode(Y_bl,SE);
% e_s is then thresholded to obtain a binary edge image g1 = [-1 0 1]; g2 = [-1;0;1]; s = uint8(max(abs(conv2(double(e_s),double(g1),'same')),abs(conv2(double(e_s),double(g2),'same')))); gamma = double(sum(sum(s.*e_s)))/double(sum(s(:))); %fprintf('\ngamma = %8.3f\n',gamma); edge0 = im2bw(e_s,gamma/double(max(e_s(:))));
%clear SE Y_bl e_s;
fprintf('\nProcessing Time: %8.3f sec\n',toc);
% A close operation before analyze the regions edge1 = imclose(edge0,ones(3,3)); %edge1 = edge0; %clear edge0;
% Regionprops operations [L1 num1] = bwlabel(edge1,4); R1 = regionprops(L1,'BoundingBox','Area'); %Major1 = regionprops(L1,'MajorAxisLength'); %Minor1 = regionprops(L1,'MinorAxisLength');
[pixNum_h ,pixNum_w] = size(edge1); edge_m = zeros(pixNum_h, pixNum_w); S = []; fprintf('before loop %d',num1); %num1=1; for i = 1:num1 fprintf('entering into loop');
% box = R1(i).BoundingBox; %area = R1(i).Area; box = R1(i).BoundingBox;
area = R1(i).Area;
box_w = box(3); box_h = box(4); box_ratio = box_w / box_h; area_ratio = area / box_w / box_h; center_w = (box(1) + box(3)/2)/pixNum_w; center_h = (box(2) + box(4)/2)/pixNum_h;
fprintf('\nwidth: %d\n',center_w); fprintf('\nheight: %d\n',center_h); %{ major = Major1(i).MajorAxisLength; minor = Minor1(i).MinorAxisLength;
if (major / minor > 6) continue; end %} if ((center_w>0.15)&&(center_w<0.85)&&(center_h>0.2)&&(center_h<0.8)) % position filter %if ((center_h>0.2)&&(center_h<0.8)) % position filter if ((box_ratio<10)&&(box_w<0.5*pixNum_w)&&(box_w>10)) if ((box_h<0.3*pixNum_h)&&(box_h>15)) if (area_ratio>0.1)% geometry filter %edge_m(L1==i) = 1; edge_m(uint16(box(2):(box(2)+box(4))),uint16(box(1):(box(1)+box(3)))) = 1; fprintf('\nnumber: %d\n',i); % S = [S ; box i]; % save bounding box information of the candidates end end end end end S = [S ; box i]; % save bounding box information of the candidates %clear Bounding1 Area1; fprintf('hellow how r u?');
% if size(S,1) < 1 % % break; % end
mean_h1 = mean(S(:,4)); % the mean height of all boxes
std_h1 = std(S(:,4)); % the standard deviation for i = 1:size(S,1) if (S(i,4) < mean_h1*0.6)||(S(i,4) > mean_h1*1.8) % remove candidate from mask if the height is beyond mean +/- 2*std edge_m(uint16(S(i,2):(S(i,2)+S(i,4))),uint16(S(i,1):(S(i,1)+S(i,3)))) = 0; end end
edge_m2 = imclose(edge_m, ones(1,1.5*uint16(mean_h1)));
% Analyze word candidates [L3 ,num3] = bwlabel(edge_m2,4); R3 = regionprops(L3,'BoundingBox','Area');
Y2 = false(size(Y)); sum_w3 = 0; sum_h3 = 0; for i = 1:num3 box = R3(i).BoundingBox; sum_w3 = sum_w3 + box(3); sum_h3 = sum_h3 + box(4); end mean_w3 = double(sum_w3) / num3; mean_h3 = double(sum_h3) / num3;
for i = 1:num3 box = R3(i).BoundingBox; area = R3(i).Area;
% if width is not like other texts in the image, skip if (box(3) < mean_w3/3) continue; end %{ % if height is not like other texts in the image, skip if (box(4) < mean_h3/3) continue; end %} % if width / height is too small, not likely to be text, skip if (box(3)/box(4) < 1) continue; end % if area ratio is too small, not likely to be text, skip if (area / box(3) /box(4) < 0.6) continue; end
h_low = dsRate*(max(uint16(box(2)),1)-1)+1; h_high = dsRate*min(uint16(box(2)+box(4)),pixNum_h); w_low = dsRate*(max(uint16(box(1)),1)-1)+1; w_high = dsRate*min(uint16(box(1)+box(3)),pixNum_w);
word_a = Y(h_low:h_high,w_low:w_high);
thresh = graythresh(word_a);
% TRY TO ADD LOCAL THRESHOLD HERE!!!!! % TRY TO ADD LOCAL THRESHOLD HERE!!!!! varThresh = 30; numInX = 5; numInY = 1; globalThresh = 255 * graythresh(word_a); windowSizeX = floor(size(word_a,2)/numInX); windowSizeY = floor(size(word_a,1)/numInY); %I_t = uint8(size(word_a)); I_t = uint8(zeros(numInY,numInX)); for j = 1: numInX if (j == numInX) x1 = (numInX -1) * windowSizeX + 1; x2 = size(word_a,2); else x1 = (j-1) * windowSizeX + 1; x2 = j * windowSizeX; end
for k = 1: numInY if (k == numInY) y1 = (k-1) * windowSizeY + 1; y2 = k * windowSizeY; else y1 = (k-1) * windowSizeY + 1; y2 = size(word_a,1); end localI = word_a(y1:y2,x1:x2); % If variance greater than a certain value % Do Otsu's method if var(double(localI(:))) > varThresh level = graythresh(localI(:)); %I_t(y1:y2,x1:x2) = 255 * level; I_t(k,j) = 255 * level; % Else, consider the region as uniform forground / background else %I_t(y1:y2,x1:x2) = globalThresh; I_t(k,j) = 100; end end end
I_t_r = imresize(I_t,size(word_a),'bilinear'); % word_b = im2bw(word_a,max(0.1,thresh-0.05)); % ver 5 word_b = (word_a > I_t_r);
% Switch B/W for background / foreground backW = 0; [hh ww] = size(word_b); if (word_b(1,1) == 1) backW = backW + 1; end if (word_b(1,ww) == 1) backW = backW + 1; end if (word_b(hh,1) == 1) backW = backW + 1; end if (word_b(hh,ww) == 1) backW = backW + 1; end if (backW <= 2) word_b = ~word_b; end
opSize = (h_high-h_low)/40; % size for further open/close operations if (opSize >= 2) word_c = imopen(~imopen(word_b,ones(opSize,opSize)),ones(opSize,opSize)); % Add in ver 5 else word_c = ~word_b; end Y2(h_low:h_high,w_low:w_high) = word_c; ketan=input('enter the text') saveName = strcat('processedImages/',fileName,'_',num2str(i,'%#02i'),'_v5.jpg'); %imwrite(word_c,saveName,'jpg'); end
%clear Bounding3 Area3;
%%%%%%%%%%%%%%%%%%%%% %Y4 = imclose(Y3, ones(15,15)); % Add in ver 5, can solve the Net-like obstacle problem, but not recommended for universal usage %%%%%%%%%%%%%%%%%%%%%
%imwrite(Y3,strcat('processedImages/',fileName,'_',t_v4.jpg'));
%I_out = something; %clear edge1 edge_m edge_m2 Y Y2;
% Print the time elapsed fprintf('\nProcessing Time: %8.3f sec\n',toc); fprintf('end of the program');

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by