Hello,
I have a cell array (2 x 6) called "output", each cell in row #1 {1 -> 6, 2} contains a 1024 x 1024 x 100 matrix. I want to apply movmedian to each cells in row #1. I would like to apply this function in dimension = 3 with window size = 5.
output = cellfun(@movmedian(5,3), output,'uniform', 0);
This is the code that I have come up with so far, however, it produces an "unbalenced or unexpected parenthesis or bracket" error. I am unsure what is causing this error. I am also somewhat unsure how to instruct matlab to perform this operation only on row 1 of the cell array, please help!
Thank you for your time!!

댓글 수: 4

Jan
Jan 2017년 8월 24일
편집: Jan 2017년 8월 24일
I still do not understand the notation "each cell in row #1 {1 -> 6, 2}". Please do not invent new terms without explaining it. The "row 1" of the cell C is "C(1, :)" [EDITED, was C(:,1)]. You can assume, that all readers are familiar with the Matlab syntax.
itend
itend 2017년 8월 24일
Got it. Thank you for the advice!
Image Analyst
Image Analyst 2017년 8월 24일
You say C is an array of cells with 2 rows of 6 columns ("2x6").
C(:,1) is a column vector of the 2 cells in column #
C(1,:) is a row vector of the 6 cells in row #1.
C(expression, 2) is a column vector extracted from only the rows identified in "expression" and only from column #2. So it would have either one cell or two cells since there are only two rows.
Not sure what you mean, but it's clear that reading this FAQ item might help: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
itend
itend 2017년 8월 25일
Thank you for your response.
I was interested in C(1,:), the row vector of 6 cells in row 1.

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

 채택된 답변

Jan
Jan 2017년 8월 24일
편집: Jan 2017년 8월 24일

0 개 추천

output(:, 1) = cellfun(@(c) movmedian(c, 5, 3), output(:, 1), 'uniform', 0);
Remember, that cellfun is very nice, but less efficient than a simply loop in general. Try this:
for k = 1:size(output, 1)
output{k, 1} = movmedian(output{k, 1}, 5, 3);
end
I prefer to keep it simple stupid, most of all if it takes less runtime in addition.

댓글 수: 5

itend
itend 2017년 8월 24일
편집: itend 2017년 8월 24일
Thank you for your help!
There seems, however, to be an issue... after running your code, it doesn't seem to affect "output". I was expecting the matrices to be changed to 1024 x 1024 x 19. I have attached a pic of my matlab screen for reference.
Also, I apologize if I wasn't clear in my initial post. I am interested in applying movmedian to output(1,:).
What do you think?
Jan
Jan 2017년 8월 24일
편집: Jan 2017년 8월 24일
@itend: There is no reason for apologies. All question concerning Matlab are welcome in the forum and questions for clarifications belong to the standard for solving problems. The communication about a powerful language like Matlab is not trivial, we know this. :-)
Please prefer to post text as text, not as screenshot. When I open the image, I loose the text I'm currently typing.
The output of movmedian has the same size than the input. I assume that you do not want the "moving", but the "block-wise" median over 5 elements:
for k = 1:size(output, 1)
C = output{k, 1};
C = reshape(C, [size(C, 1), size(C, 2), 5, size(C, 3) / 5]);
output{k, 1} = squeeze(median(C, 3));
end
itend
itend 2017년 8월 24일
Ok! Thank you for your kindness.
For ease of vocabulary, each of the (1024 x 1024) matrices represents an image frame. The 3D array represents 100 image frames taken over time. I thought that the movmedian function would replace a given pixel in each 1024 x 1024 matrix with the median of that pixel taken over 5 frames. Am I incorrect? If so, what is another approach to solving this problem?
Thanks again!!!
Image Analyst
Image Analyst 2017년 8월 24일
Two questions:
  1. Why are you using a cell array to store all the frames? I see no need for that.
  2. Why aren't you using medfilt2() to do a median filter on your images?
itend
itend 2017년 8월 25일
1) The idea is that I use a cell array to store each image, then perform operations such as background subtraction to all entries within the cell array. How would you recommend storing/processing the images?
2) I actually figured out how to modify the parameters of movmedian to solve the issue I was having.
Thanks!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

질문:

2017년 8월 24일

댓글:

2017년 8월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by