I want to create a prototype which contains all the characters present in the image. But the condition is that repeating characters should be displayed only once. Can I get a code for this.
  • for example if in a image character "t" occurs multiple times it should be displayed once in the prototype
  • please do give me a matlab code to display the prototype image
  1. I have attached the code file("doc1.txt") please help me to proceed.
................... Please help me out to eliminate repeating characters from the image.
I want the output something like this " t e x p u b l i s h n g " >>>>>>>>>in image format

8 commentaires

Stephen23
Stephen23 le 21 Juil 2017
@stark iron: what is the expected output?
Guillaume
Guillaume le 21 Juil 2017
Is this question about parsing text strings (e.g from a unicode text file) or optical character recognition in images?
stark iron
stark iron le 21 Juil 2017
@Stephen Cobeldick i want the output as
t e x p u b l i s h n g
in the image format.... repeating characters should be displayed once
stark iron
stark iron le 21 Juil 2017
@Guillaume its about OCR. can i also know how to calculate the ratio of bounding box... ratio=Length/breadth
stark iron
stark iron le 23 Juil 2017
@Image Analyst is the excepted output possible??
Walter Roberson
Walter Roberson le 23 Juil 2017
Given what you have written, the output should be 0 t _ e x p u b l i s h n g
stark iron
stark iron le 24 Juil 2017
@Walter Roberson I didn't get the excepted output

Connectez-vous pour commenter.

 Réponse acceptée

Image Analyst
Image Analyst le 23 Juil 2017

0 votes

What I would do is to threshold and label all the character blobs in your image. Then use regionprops() to measure the centroid and things like area, Euler number, solidity. Then see if there are any duplicates of the things (other than the centroid of course). If there is a match, remove duplicates by overwriting the label with 0 in the labeled image. Use the x centroid to determine which is the first (left most) blob.

6 commentaires

stark iron
stark iron le 24 Juil 2017
thank you!! @Image Analyst...but I'm not able to do it. I'm not getting the excepted output
Image Analyst
Image Analyst le 24 Juil 2017
I can't fix your code without your code. Please attach what you did.
stark iron
stark iron le 24 Juil 2017
@Image Analyst I have attached my code file-'code1.txt' ....thank you
Image Analyst
Image Analyst le 24 Juil 2017
But that code is no good. Did you try to implement the algorithm I gave you?
Alright, here's a start. There are some problems that you'll have to deal with when you take over the code, like the p and b have the same features with the ones I picked so you'll have to add some more, and the x and the t are connected. But since you're a brilliant engineer, I'm sure you'll have those figured out in no time. I need to get to bed now - it's late. Here is the code for you to finish:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 25;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'textpublishing.png';
% Get the full filename, with path prepended.
folder = []; % Determine where demo folder is (works with all versions).
fullFileName = fullfile(folder, baseFileName);
%===============================================================================
% Read in a demo image.
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
axis image;
caption = sprintf('Original Gray Scale Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
binaryImage = grayImage > 0;
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage, []);
axis on;
axis image;
% Label the blobs
[labeledImage, numBlobs] = bwlabel(binaryImage);
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
% coloredLabels is an RGB image. We could have applied a colormap instead (but only with R2014b and later)
subplot(2, 2, 3);
imshow(coloredLabels);
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
caption = sprintf('Pseudo colored labels, from label2rgb().\nBlobs are numbered from top to bottom, then from left to right.');
title(caption, 'FontSize', fontSize);
% Make measurements of area and solidity
props = regionprops(labeledImage, 'Area', 'Solidity', 'Perimeter', 'Image');
allAreas = [props.Area]
allSolidities = [props.Solidity]
allPerimeters = [props.Perimeter]
% Go through the blobs seeing if any blob is within 10% of any prior blob
promptMessage = sprintf('Do you want to Continue processing,\nor Quit processing?');
titleBarCaption = 'Continue?';
subplot(2, 2, 4);
for k = 2 : numBlobs
imshow(props(k).Image);
axis on;
caption = sprintf('Checking blob #%d against blobs #1 - %d', k, k-1)
title(caption, 'FontSize', fontSize);
thisArea = allAreas(k);
areaDifferences = abs((allAreas(1:k-1) - thisArea) / thisArea)
thisSolidity = allSolidities(k);
solidityDifferences = abs((allSolidities(1:k-1) - thisSolidity) / thisSolidity)
thisPerimeter = allPerimeters(k);
perimeterDifferences = abs((allPerimeters(1:k-1) - thisPerimeter) / thisPerimeter)
areaMatches = areaDifferences < 0.1;
solidityMatches = solidityDifferences < 0.1;
perimeterMatches = perimeterDifferences < 0.1;
% Find out where BOTH area and solidity are within 10%
matchingIndexes = find(areaMatches & solidityMatches & perimeterMatches);
if ~isempty(matchingIndexes)
% At least one match was found.
for k2 = 1 : length(matchingIndexes)
message = sprintf('Blob #%d matches blob #%d', k, matchingIndexes(k2));
buttonText = questdlg(message, titleBarCaption, 'Continue', 'Quit', 'Continue');
if strcmpi(buttonText, 'Quit')
return;
end
end
end
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if strcmpi(buttonText, 'Quit')
break;
end
end
stark iron
stark iron le 26 Juil 2017
Modifié(e) : stark iron le 26 Juil 2017
@Image Analyst thank you so much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by