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

조회 수: 2 (최근 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 CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by