필터 지우기
필터 지우기

Code shows"Integer operands are required for colon operator when used as index "

조회 수: 2 (최근 30일)
IPlover
IPlover 2013년 11월 21일
댓글: Walter Roberson 2013년 11월 22일
Here is an code which i've written but it shows a warning and stops executing. I tried using round for 'noise' variable,still the code didn't work.
% Load image img = imread('gel.png'); img = rgb2gray(img);
% Identify lanes
imshow(img)
[x,y] = ginput;
% Invert image
img = max(img(:)) - img;
% Subtract background
[xn,yn] = ginput(1);
noise = img((yn-2):(yn+2), (xn-2):(xn+2));
noise = mean(noise(:));
img = img - noise;
% Calculate means
means = (1:size(img,1)) * double(img(:,round(x))) ./ sum(double(img(:,round(x))), 1);
% Plot
hold on
plot(x, means, 'r.')
  댓글 수: 4
IPlover
IPlover 2013년 11월 22일
Please help ASAP as within a few hours i have to get the code running.

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

답변 (1개)

Image Analyst
Image Analyst 2013년 11월 22일
gniput returns fractional floating point values. But then you try to use it as an index (yn-2):(yn+2). That won't work if yn = 42.34567. Try casting to int32 first before using as an index.
yn = int32(in);
  댓글 수: 2
IPlover
IPlover 2013년 11월 22일
편집: Walter Roberson 2013년 11월 22일
I tried again and it is still showing error
% Load image
img = imread('c.jpg');
img = rgb2gray(img);
% Identify lanes
imshow(img)
[x,y] = ginput;
% Invert image
img = max(img(:)) - img;
% Subtract background
yn=int32(in);
[xn,yn] = ginput(1);
noise = img((yn-2):(yn+2), (xn-2):(xn+2));
noise = mean(noise(:));
img = img - noise;
% Calculate means
means = (1:size(img,1)) * double(img(:,round(x))) ./ sum(double(img(:,round(x))), 1);
% Plot
hold on
plot(x, means, 'r.')
Walter Roberson
Walter Roberson 2013년 11월 22일
You do the ginput, and then you calculate yn as integral valued from it, and then you immediately write over yn and use the floating value from it. You should do this:
[x,y] = ginput;
xnl = max(ceil(x)-2, 1);
xnh = min(floor(x)+2, size(img,2));
ynl = max(ceil(y)-2, 1);
ynh = min(floor(x)+2, size(img,1));
noise = imag(ynl:ynh, xnl:xnh);
noise = mean(noise(:));
means = (1:size(img,1)) * mean(double(img(:,ceil(x))));
I don't know why you are weighting the means by the row number?
The choice of floor() and ceil() that I used was to maximize the likelihood that the calculation would stay inside the array. I then added min() and max() to force it to be inside on the boundaries. Except that I didn't bother to code it for the means: really you should make sure it is in the array, but as you have seen the pattern now you can modify the code yourself.

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

Community Treasure Hunt

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

Start Hunting!

Translated by