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:

답변 (1개)

Image Analyst
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
Nivetha m
Nivetha m 2016년 4월 24일
% 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:
Image Analyst
Image Analyst 2016년 4월 24일
That's a 7 year old version! MATLAB has progressed quite a bit since then. Time to upgrade.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by