I assign A = B; but I could not use A and B interchangeably

조회 수: 1 (최근 30일)
Khoa Nguyen
Khoa Nguyen 2019년 9월 6일
댓글: Matt J 2019년 9월 6일
Hi everyone,
I'm trying to make a 3D median filter for a 3D CT image, here is my code:
function I_fted = abc(img, mar)
I_fted = img;
% For-loop to loop through each pixel in x,y,z directions and filtration
for y = 1+mar:size(img,1)-mar %loop through the vertical direction
for x = 1+mar:size(img,2)-mar %loop through the horizontal direction
for z = 1+mar:size(img,3)-mar %loop through the slices
grid = img(y-mar:y+mar, x-mar:x+mar,z-mar:z+mar); %create a cubic grid [mar x mar x mar]
I_fted(y,x,z) = median(grid(:)); %calculate the median of the pixels inside cubic grid
end
end
end
end
I did assign I_fted = img. However, when I use the below commands, the result images are different for each case. I don't know why
% Case 1:
grid = img(y-mar:y+mar, x-mar:x+mar,z-mar:z+mar); %this give different result to the below
% Case 2:
grid = I_fted(y-mar:y+mar, x-mar:x+mar,z-mar:z+mar);
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 9월 6일
At what point do they become different? You are changing I_fted
By the way, have you considered using nlfilter()

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

채택된 답변

James Tursa
James Tursa 2019년 9월 6일
You are changing I_fted inside the loop. If you subsequently use it in another calculation within the loop, it would not be surprising that the results are different from what you would get using img, which was not changed within the loop.
  댓글 수: 2
Khoa Nguyen
Khoa Nguyen 2019년 9월 6일
Thanks a lot, it makes sense
Matt J
Matt J 2019년 9월 6일
@Khoa,
Since you seem to be satisfied with James' answer, you should Accept-click it.

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

추가 답변 (0개)

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by