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 回表示 (過去 30 日間)
古いコメントを表示
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:
0 件のコメント
回答 (1 件)
Image Analyst
2016 年 4 月 23 日
Try my attached demo. I think it might work well for you if you tweak some of the parameters.
5 件のコメント
Image Analyst
2016 年 4 月 24 日
That's a 7 year old version! MATLAB has progressed quite a bit since then. Time to upgrade.
参考
カテゴリ
Help Center および File Exchange で Computer Vision with Simulink についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!