Replacing elements in a matrix in an if-else statement?

5 次查看(过去 30 天)
I have an assignment where I am supposed to make a function that will take a photo of myself, with a sharply contrasting background, pick out the image of me, and place it into another image (mine is of Pluto) like a fake tourist photo. This is my code so far:
stub=pluto(151:end,52:111,:);
for i=1:numel(stub)
if me(i) >= 229;
stub(i)=stub(i);
else
stub(i)=me(i);
end
end
The "stub" is a piece of the Pluto image that is the same size as my photo, so I was attempting to pick out the threshold of my photo with the if statement and replace its values with my photo. The background of my photo is a bright green, hence the 229 value. I have also tried this code with a for loop through every row, column, and 3rd dimension, and tried to pick out only the value in the green layer, but for that attempt and the code above I keep getting strange results that are not what I need. Which is the better approach, and what is it that I'm doing wrong?
Thanks!
  2 个评论
Chad Greene
Chad Greene 2016-3-2
This sounds like a fun project. I have a feeling the loop and the if statement are both unnecessary, but just to check, I need to ask,
1. It looks like your Pluto image is RGB because it has a third dimension. Is that true?
2. Is the photo of you RGB or grayscale?
3. Assuming the photo of you is RGB, what are the RGB values of the background?
Janell Lopez
Janell Lopez 2016-3-3
Both are RGB. It's a beginner's class, so I think the for loop is implied, but if there's another way I'm all ears! The value of the background is a bright green, with R=181, G=229, B=29.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by