필터 지우기
필터 지우기

Problem in calculation formula

조회 수: 1 (최근 30일)
Syakira Akmal
Syakira Akmal 2017년 4월 4일
댓글: Guillaume 2017년 4월 5일
Hi, this my problem. "Subscript indices must either be real positive integers or logicals. Error in tryMVM (line23) s=sum(y(X-i,Y-j)-mean)". X and Y is my point. How can i convert double to logical?
  댓글 수: 2
KSSV
KSSV 2017년 4월 4일
Show us the full code......we cannot help unless full code is known.
Syakira Akmal
Syakira Akmal 2017년 4월 5일
this is my coding..
a = imread('snake4.JPG');
imshow(a);
x = roipoly(a);
figure, imshow(x);
y = imresize(x,0.5);
figure, imshow(y);
imwrite(y,'s1.jpg');
%to set point
[X,Y] = meshgrid(1:1224,1:1224);
%to calculate mean image
b = imread('s1.jpg');
m = mean2(b)
%to calculate standard deviation
c = imread('s1.jpg');
sd = std2(c)
%mean-variance moving window operation
for i=1:1224
for j=1:1224
s=sum(y(X-i,Y-j)-m) %problem
end

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

채택된 답변

Guillaume
Guillaume 2017년 4월 4일
The problem you have is not that your subscripts are not logical, it is that either they're not positive or they're not integers. I'm fairly certain, even with the very limited info you've provided, that converting to logical won't give you the result you want.
So,
  • make sure that X, Y, i and j are integers
  • make sure that X > i and Y > j
  • and, you never know, make sure that you haven't got a variable called sum that stops you from using the sum function.
And on that last point, don't use mean as a variable name since it prevents you from using the mean function.
  댓글 수: 2
Syakira Akmal
Syakira Akmal 2017년 4월 5일
this is my coding..
a = imread('snake4.JPG');
imshow(a);
x = roipoly(a);
figure, imshow(x);
y = imresize(x,0.5);
figure, imshow(y);
imwrite(y,'s1.jpg');
%to set point
[X,Y] = meshgrid(1:1224,1:1224);
%to calculate mean image
b = imread('s1.jpg');
m = mean2(b)
%to calculate standard deviation
c = imread('s1.jpg');
sd = std2(c)
%mean-variance moving window operation
for i=1:1224
for j=1:1224
s=sum(y(X-i,Y-j)-m) %problem
end
I still cannot solve the problem...
Guillaume
Guillaume 2017년 4월 5일
Well, yes that code is not going to work. X(1) is 1, so for any i, the expression X-i is always going to result in at least one value less than 1. When i is 1224, none of the values in X-i are valid indices.
In any case, nothing in that loop makes sense and I've no idea what you're trying to achieve. If you're trying to find the mean of the image over a moving window then you can use conv2:
%mean of image over sliding window of size mxn:
conv2(img, ones(m, n)/(m*n))

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by