Programming error?
Show older comments
My problem is that I have an image which I uploads. I want to obtain the line profile (intensity) for a certain leaning line of my choice.
My error arises when I am obtaining the intensity profile (mode_vecX). See code below..., also I have to round of my y-vector. Is that needed?
% Uploads the Image to a vector:
image_vec = imread(image_filename);
% Creates the coordinate vectors of the image
pixlength_vecX = 1:length(image_vec(:,1));
pixlength_vecY = 1:length(image_vec(1,:));
% Obtains the points which you want the slope between:
disp('Please pick two points along the line profile you want to investigate: ');
imshow(image_vec);
title('Please pick two points along the line profile you want to investigate: ');
xlabel('x pixel');
ylabel('y pixel');
[x,y] = ginput(2);
close all
% Finds the line's equation y = m*x + k
p = polyfit(x,y,1);
yPixel_vec = polyval(p,pixlength_vecY); %
% Obtains the intensity at coordinate (x,y)
mode_vecX = image_vec(pixlength_vecY,round(yPixel_vec));
The error message I get when I run this is:
??? Index exceeds matrix dimensions.
Error in ==> imageProfile at 69 mode_vecX = image_vec(pixlength_vecY,round(yPixel_vec));
Something is wrong here and I need some other thoughts and eyes. Many thanks for the assistance.
Accepted Answer
More Answers (1)
Jan
on 2 Aug 2011
I assume you have confused the 1st and 2nd dimension and the 1st argument must be "pixlength_vecX" in this line:
% Buggy:
mode_vecX = image_vec(pixlength_vecY, round(yPixel_vec))
To solve such problems by your own, let the debugger stop MATLAB, when the error occurs:
dbstop if error
Then inspect, why either "pixlength_vecY" or "round(yPixel_vec)" exceeds the dimensions of image_vec.
This forum cannot replace a debugger and it is up to you to fix your programs as far as possible.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!