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

1 回表示 (過去 30 日間)
Janell Lopez
Janell Lopez 2016 年 3 月 1 日
コメント済み: Janell Lopez 2016 年 3 月 3 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by