i've an error at 22nd number line. may i need to count the lines from 1,2,3,... 22 to find out it?

조회 수: 1 (최근 30일)
close all; % Close all figures (except those of imtool.) imtool close all; % Close all imtool figures. clear; % Erase all existing variables. workspace; % Make sure the workspace panel is showing. format longg; 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 color demo image. folder = fullfile(matlabroot, 'E:\4-1\implementation\my_matlab'); baseFileName = 'rec.jpg'; % Get the full filename, with path prepended. fullFileName = fullfile(folder, baseFileName); if ~exist(fullFileName, 'file') % Didn't find it there. Check the search path for it. fullFileName = baseFileName; % No path this time. if ~exist(fullFileName, 'file') % Still didn't find it. Alert user. errorMessage = sprintf('Error: %s does not exist.', fullFileName); uiwait(warndlg(errorMessage)); return; end end rgbImage = imread(fullFileName); % Get the dimensions of the image. numberOfColorBands should be = 3. [rows columns numberOfColorBands] = size(rgbImage); % Display the original color image. subplot(2, 2, 1); imshow(rgbImage, []); axis on; title('Original Color Image', 'FontSize', fontSize); % Enlarge figure to full screen. set(gcf, 'units','normalized','outerposition',[0 0 1 1]); smallSubImage = imcrop(rgbImage, [192 82 60 52]); subplot(2, 2, 2); imshow(smallSubImage, []); axis on; title('Template Image to Search For', 'FontSize', fontSize); % Search the red channel for a match. correlationOutput = normxcorr2(smallSubImage(:,:,1), rgbImage(:,:,1)); subplot(2, 2, 3); imshow(correlationOutput, []); title('Correlation Output', 'FontSize', fontSize); [maxCorrValue, maxIndex] = max(abs(correlationOutput(:))); [ypeak, xpeak] = ind2sub(size(correlationOutput),maxIndex(1)); corr_offset = [(xpeak-size(smallSubImage,2)) (ypeak-size(smallSubImage,1))]; subplot(2, 2, 4); imshow(rgbImage); hold on; rectangle('position',[corr_offset(1) corr_offset(2) 50 50],... 'edgecolor','g','linewidth',2); title('Template Image Found in Original Image', 'FontSize', fontSize);
this code has an error in 22nd number line.
  댓글 수: 1
Tobias
Tobias 2013년 4월 28일
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
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 color demo image.
folder = fullfile(matlabroot, 'E:\4-1\implementation\my_matlab');
baseFileName = 'rec.jpg'; % Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file') % Didn't find it there. Check the search path for it. fullFileName = baseFileName; % No path this time. if ~exist(fullFileName, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName); % Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage); % Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage, []);
axis on;
title('Original Color Image', 'FontSize', fontSize); % Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
smallSubImage = imcrop(rgbImage, [192 82 60 52]);
subplot(2, 2, 2); imshow(smallSubImage, []);
axis on;
title('Template Image to Search For', 'FontSize', fontSize); % Search the red channel for a match.
correlationOutput = normxcorr2(smallSubImage(:,:,1), rgbImage(:,:,1));
subplot(2, 2, 3);
imshow(correlationOutput, []);
title('Correlation Output', 'FontSize', fontSize);
[maxCorrValue, maxIndex] = max(abs(correlationOutput(:)));
[ypeak, xpeak] = ind2sub(size(correlationOutput),maxIndex(1));
corr_offset = [(xpeak-size(smallSubImage,2)) (ypeak-size(smallSubImage,1))];
subplot(2, 2, 4);
imshow(rgbImage);
hold on;
rectangle('position',[corr_offset(1) corr_offset(2) 50 50],... 'edgecolor','g','linewidth',2);
title('Template Image Found in Original Image', 'FontSize', fontSize);
You didn't read about how to properly post your code, did you?

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

채택된 답변

Tobias
Tobias 2013년 4월 28일
You do not need to count lines. If you have your file open in the MATLAB editor, you should see the line count to the far left of your code. MATLAB will display the exact line where your error is found.

추가 답변 (1개)

Jan
Jan 2013년 4월 28일
Usually the error messages in the command window are written as hyperlinks, such that clicking on the underlined part move the cursor directly to the corresponding line. Therefore you do not have to count the lines.
In addition the number of the current line is displayed at the bottom of the editor also.

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by