Replacing elements in a matrix in an if-else statement?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Chad Greene
el 2 de Mzo. de 2016
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?
Respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!