필터 지우기
필터 지우기

How to find the co-ordinates in an image?

조회 수: 1 (최근 30일)
sindhu c
sindhu c 2015년 11월 28일
댓글: Meghashree G 2015년 12월 17일
In the attached image,how do i find the co-ordinates of first letter(i.e. starting balck pixel of 'a') and co-ordinates of last letter?(i.e.last pixel of letter 'e') Please help me Thank you

채택된 답변

Image Analyst
Image Analyst 2015년 11월 28일
Try this:
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 long g;
format compact;
fontSize = 20;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in a standard MATLAB gray scale demo image.
folder = pwd;
baseFileName = 'oneline.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% 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')
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(grayLevels, pixelCount); % Plot it as a bar chart.
grid on;
title('Histogram of original image', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Gray Level', 'FontSize', fontSize);
ylabel('Pixel Count', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Get a horizontal profile
horizontalProfile = sum(grayImage, 1) / rows;
% Threshold the image and create a binary image
subplot(2, 2, 3);
x = 1:length(horizontalProfile);
plot(x, horizontalProfile, 'b-', 'LineWidth', 2); % Plot it as a line.
grid on;
title('Profile of original image', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Column Number', 'FontSize', fontSize);
ylabel('Gray Level', 'FontSize', fontSize);
% Threshold at 240
theThreshold = 240;
inAWord = find(horizontalProfile < theThreshold)
% Draw a red line over the plot
hold on;
plot([x(1), x(end)], [theThreshold, theThreshold], 'r-', 'LineWidth', 2); % Plot it as a line.
% Determine the left and right-most columns:
leftColumn = inAWord(1);
rightColumn = inAWord(end);
% Display the original gray scale image.
subplot(2, 2, 4);
imshow(grayImage, []);
axis on;
title('Image with detected words', 'FontSize', fontSize, 'Interpreter', 'None');
% Put up shaded areas over words
hold on;
for k = 1 : length(inAWord)
col = inAWord(k);
fill([col, col], [1, rows], 'y', 'FaceAlpha', 0.1, 'EdgeColor', 'y');
end
message = sprintf('The left column = %d\nThe right column = %d', leftColumn, rightColumn);
uiwait(helpdlg(message));
  댓글 수: 9
Image Analyst
Image Analyst 2015년 12월 17일
What is endingX? Maybe later today I can download the image and code and try it for you. No guarantees though.
Meghashree G
Meghashree G 2015년 12월 17일
endingX = 1 + find(diff(logicalIndexes) < 0); This one which you gave,...And i would be grateful for that.Please do try when you are free

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by