Removing object from image using median filter

My function needs to remove an object from an image and the input is multiple images in the form of a 1xn 1D cell array containing 3D arrays of uint8 values e.g
{557x495x3} {557x495x3} {557x495x3}
The objective is to use a median filter (I've already created this code) to calculate the median pixels and store in array, so that the person/object is removed from image. The output is one RGB image where the person is removed from the image. I was wondering how to approach this?

2 件のコメント

Matt J
Matt J 2019 年 9 月 9 日
編集済み: Matt J 2019 年 9 月 9 日
Here are the example images which somehow got deleted from the original post.
Peter Bier
Peter Bier 2019 年 9 月 11 日
This is a reminder to all 131 students that as mentioned in class you need to write your own code for the project that is due shortly (rather than getting code written by one of the kind folks who answer questions on the mathworks forum). Copying any of the supplied code from below and submitting it as your own will be detected by our plagiarism detection software when we come to mark the project.

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2019 年 9 月 8 日

2 投票

I'll call your 1xn cell array of images ImageCell. Then I think you want,
Image4D=cat(4,ImageCell{:});
R=median( Image4D(:,:,1,:) , 4);
G=median( Image4D(:,:,2,:) , 4);
B=median( Image4D(:,:,3,:) , 4);
finalImage=cat(3, R,G,B);

7 件のコメント

Sara Foster
Sara Foster 2019 年 9 月 8 日
Thanks, it works! But how does this code work?
Matt J
Matt J 2019 年 9 月 8 日
編集済み: Matt J 2019 年 9 月 8 日
Well, if you'll notice, the entire code uses only two commands, cat and median. The documentation on these commands should make it very decipherable.
But basically, we concatenate all your images into a 4D array and take the median of each color channel along the 4th dimension.
Sara Foster
Sara Foster 2019 年 9 月 9 日
編集済み: Sara Foster 2019 年 9 月 9 日
Thanks again, I was also wondering if there are any possible alternatives to convert the 3D array to a 4D array regarding the first line?
Also is there any way to make it a for loop instead?
Matt J
Matt J 2019 年 9 月 9 日
You might perhaps be able to devise alternatives using loops, but it would serve no purpose. The version with cat is quite efficient.
Sara Foster
Sara Foster 2019 年 9 月 9 日
Yeah it would minimise the run time, but I need to create another function which calculates the greatest squared distance from the median pixel, so I’m unsure how to work this for my code. The greatest squared pixel distance is (P1-Q1)^2 + (P2-Q2)^2 + (P3-Q3)^2, so it’s the corresponding pixel most furtherest away from the median pixel. The objective of the function is to have multiple images as inputs e.g (the person in the three pictures) and combine it to one to create an action shot e.g. (there will be three of the same person in the one image displayed).
Matt J
Matt J 2019 年 9 月 9 日
編集済み: Matt J 2019 年 9 月 9 日
Well, you should probably describe that task in more detail in a separate post, because it sounds like it will need a lot more explanation. It is certainly a completely different goal from the object removal task that you've pursued here.
Sara Foster
Sara Foster 2019 年 9 月 9 日
Sorry, my bad. I've created a separate post.

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2019 年 9 月 8 日

コメント済み:

2019 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by