My project is on extracting text from image. i try below code but i did not get clear output , i get only noisy text image , please help me to solve my proplem

1 view (last 30 days)
clc clear all close all %---------------- format long g; format compact; fontSize = 20; %% ----------------------- fact=0.1; I1=imread('C:\Users\shankar\Documents\MATLAB\filtering\2.jpg'); figure(1),imshow(I1),title('Original Image', 'FontSize', fontSize); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. I2 = rgb2gray(I1); figure(2),imshow(I2),title('Original Gray Scale Image', 'FontSize', fontSize); %% noise I3 = imnoise(I2,'salt & pepper',0.02); %[rows columns] = size(I3); figure(3), imshow(I3),title('salt', 'FontSize', fontSize); %% MEDIAN I = filter2(fspecial('average',3),I3)/255; I = medfilt2(I3); figure(4),imshow(I),title('Kmedian', 'FontSize', fontSize);
%% thre--------------------------------- i=im2bw(I); imax=max(max(i)); imin=min(min(i)); %%L=fact*(imax-imin)+imin; L=((imax+imin)/2); thre=max(i,L.*ones(size(i))); colormap(gray); imagesc(i) imagesc(thre) figure(5),imshow(thre),title('THRE', 'FontSize', fontSize); %% noise I5 = imnoise(thre,'salt & pepper',0.02); [rows columns] = size(I5); figure(6), imshow(I5),title('salt', 'FontSize', fontSize); %% canny %I6 = filter2(fspecial('average',3),I5)/255; %I = medfilt2(I5); I6=edge(I5,'canny'); figure(7),imshow(I6),title('Kmedian', 'FontSize', fontSize); %% ------ PSNR CALCULATION ---------------------------------------------------------- %squaredErrorImage = (double(I) - double(thre)) .^ 2; % Display the squared error image. %subplot(2, 2, 3); %imshow(squaredErrorImage, []); %title('Squared Error Image', 'FontSize', fontSize); % Sum the Squared Image and divide by the number of elements % to get the Mean Squared Error. %mse = sum(sum(squaredErrorImage)) / (rows * columns); % Calculate PSNR (Peak Signal to Noise Ratio) from the MSE according to the formula. %PSNR = 10 * log10( 256^2 / mse); % Alert user of the answer. %message = sprintf('The mean square error is %.2f.\nThe PSNR = %.2f', mse, PSNR); %msgbox(message); %% PSNR origImg = double(I5); distImg = double(I6); [M N] = size(origImg); error = origImg - distImg; MSE = sum(sum(error .* error)) / (M * N); if(MSE > 0) PSNR = 10*log(255*255/MSE) / log(10); else PSNR = 99; end message = sprintf('The mean square error is %.2f.\nThe PSNR = %.2f', MSE, PSNR); msgbox(message);
INPUT IMAGE:
OUTPUT IMAGE:

Answers (1)

Image Analyst
Image Analyst on 23 Apr 2016
Try my attached demo. I think it might work well for you if you tweak some of the parameters.
  5 Comments
Nivetha m
Nivetha m on 24 Apr 2016
% Do a Sobel filter sobelImage=edge(grayImage,'sobel',0.1) ; %%sobelImage = imgradient(grayImage, 'Sobel'); I try below sobel filter code
code: % Display the image. subplot(2, 3, 4); imshow(sobelImage, []); title('Sobel Image', 'FontSize', fontSize);
output:

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!