How to find the co-ordinates in an image?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천

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
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
sindhu c
2015년 11월 28일
It worked! Thanks a lot
sindhu c
2015년 11월 29일
so is it (1,230) and (1690,250) are the co-ordinates of first and last letter resp?
hello sir. I tried the above code given by you to get the co-ordinates. But where are the co-ordinates?means I want it in the form of (x,y)
Image Analyst
2015년 12월 17일
y doesn't really apply since the input was already one line that had been extracted. So y1 = 1, and y2 = number of rows in the image.
For x, that's the column number and those are in the array called "inAWord."
Meghashree G
2015년 12월 17일
sir,i tried yo code.do u mean that y1=1 and y2 = 1690 .. and the array contains column 1 through 1334..how can i get the value of x1 and x2??
Image Analyst
2015년 12월 17일
편집: Image Analyst
2015년 12월 17일
No, from what I can see on the left hand side axes, the y1 was 1 and the y2 was about 110 or so.
And there are lots of x1 and x2, right? There is a pair of starting and stopping x for every "word". The inAWord array has an index for every x location that is in a word. If you want the starting and stopping x, you'd have to use something like diff() to get just those points. Something like (untested):
logicalIndexes = horizontalProfile < theThreshold
startingX = 1 + find(diff(logicalIndexes) > 0);
endingX = 1 + find(diff(logicalIndexes) < 0);
Meghashree G
2015년 12월 17일
sir,when i inserted those lines which u gave its displaying logicalIndexes values columns from through through 1703.but not getting anything when tried to display endingX
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
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개)
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
