Triangular Pyramid Image and Color it

Please Can Somebody tell me how to generate a triangular Pyramid image of 2 by 2 with height of 200 pixels and the base of 200 pixels; and Color the image in any two colors "http://www.google.com/imgres?q=triangular+Pyramid+image+of+2+by+2&hl=en&tbo=d&biw=1366&bih=541&tbm=isch&tbnid=hhxBKdNeShxfdM:&imgrefurl=http://www.analyzemath.com/calculus/Integrals/volume_square_pyramid.html&docid=Ts_z5lT0xhYuyM&imgurl=http://www.analyzemath.com/calculus/Integrals/volume_square_pyramid_2.gif&w=322&h=312&ei=j0O6UKCyKPCB0QHk_YH4CA&zoom=1&iact=hc&vpx=935&vpy=179&dur=12880&hovh=221&hovw=228&tx=102&ty=244&sig=116099075241339748532&page=1&tbnh=141&tbnw=150&start=0&ndsp=22&ved=1t:429,r:20,s:0,i:147" THIS IS AN EXAMPLE OF 2 BY 2 TRIANGULAR PYRAMID THAT I'M TALKING ABOUT. I would like to have codes that imshow a triangular Pyramid Image and color each with two diferent color such as Blue and Red. Can somebody do that.

7 个评论

What does 2 by 2 mean? You mean a really really small quantized rectangle of 2 by 2 at the center of a 200 x 200 square image? That's not really a triangle. It's just some pixels like
0 255
255 255
only 3 pixels!
this one is an Example of the Triangular Pyramid that I'm looking for, but when I copy this code top MatLab, It gives me a One by one Triangular, instead of two by two. But thank you Image Analyst, whoever your name is.
That explanation does not help at all. I still don't know what 2 by 2 means. 2 what by 2 what? Pixels? Can you try to draw the values like I did. And I'm not sure what code you copied to MATLAB. The stuff above was not code - just pixel values. And the code in my answer below draws a triangle just fine.
Oh! Do you mean you want two complete rectangles side-by-side? If so, I gave you code for one triangle below. All you have to do is repeat it with different vertices. Simple.
Yes, two complete rectangles side-by-side
Yes, two complete rectangles side-by-side. Therefore, please what is the codes.
Like I said: I gave you code for one triangle below. All you have to do is repeat it with different vertices. Simple. Just change x and y. Surely you can do that. It's so trivial that I'm not going to do it for you.

请先登录,再进行评论。

回答(1 个)

I showed you the concepts in this solution so it should not be too hard for you to adapt that. If you want to do it a different way than I did it for you there, you might look into poly2mask(), if you have the Image Processing Toolbox. In fact that's a much easier way since you have triangles.
Alright - haven't heard back from you so I guess you need more help.
x = [100 150 50];
y = [50 150 150];
redChannel = 255 * poly2mask(x, y, 200, 200);
greenChannel = 255 * ones(200);
blueChannel = zeros(200);
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
imshow(rgbImage);
axis on;
axis square;
axis image;

2 个评论

Do you have the same assignment at Walter Roberta? Cesar, I gave you the entire solution to your assignment in http://www.mathworks.com/matlabcentral/answers/63312#comment_129804. Unfortunately you can't now turn it in as your homework because I did it all for you.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by