Code shows"Integer operands are required for colon operator when used as index "
    6 次查看(过去 30 天)
  
       显示 更早的评论
    
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.')
回答(1 个)
  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 个评论
  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.
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



