現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Create a triangular image with height of 200 pixels and the base of 200 pixels and color the image in any two colors.
3 ビュー (過去 30 日間)
古いコメントを表示
Cesar
2013 年 2 月 13 日
Create a triangular image with height of 200 pixels and the base of 200 pixels and color the image in any two colors.
回答 (1 件)
Image Analyst
2013 年 2 月 13 日
Hint: use poly2mask() and logical indexing.
yourImage = zeros(rows, columns, 'uint8'); % Initialize.
% Assign values to triangle defined by "mask" image.
yourImage(mask) = someValue;
30 件のコメント
Image Analyst
2013 年 2 月 13 日
編集済み: Image Analyst
2013 年 2 月 13 日
Well, did I say to use patch()? Looks like you need more hints. Create red, green, and blue channels
color1 = [100 150 200];
redChannel = color1(1) * ones(rows, columns, 'uint8');
% Display it
imshow(redChannel);
% Draw mask, for example, call roipolyold().
Then mask it like I said, then combine them all together into an rgb image:
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
imshow(rgbImage);
See if you can complete the script on your own.
Image Analyst
2013 年 2 月 13 日
編集済み: Image Analyst
2013 年 2 月 13 日
Here is it practically done. Just 4 more lines and it's complete. You don't want me to do it completely for you do you? Would that be considered acceptable/ethical in your course?
color1 = uint8([100 150 200]);
color2 = uint8([180 50 250]);
rows = 480;
columns = 640;
redChannel = color1(1) * ones(rows, columns, 'uint8');
greenChannel = color1(2) * ones(rows, columns, 'uint8');
blueChannel = color1(3) * ones(rows, columns, 'uint8');
% Get/assign triangle vertices, triangleX, triangleY.
% I'm sure you can figure out what goes here!
% Create mask.
mask = poly2mask(triangleX, triangleY, rows, columns);
% Display mask
subplot(1,2,1);
imshow(mask);
% Assign values to triangle defined by "mask" image.
redChannel(mask) = color2(1);
% I'm sure you can figure out what goes here!
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
subplot(1,2,2);
imshow(rgbImage);
Cesar
2013 年 2 月 14 日
I use the following vertices. triangleX = [0 100 200]; triangleY = [0 200 0]; rgbImage is showing as 2 triangles instead of a single one
Image Analyst
2013 年 2 月 15 日
編集済み: Image Analyst
2013 年 2 月 15 日
You got your 2 color triangle like you wanted. The left triangle is just the mask I made with poly2mask(). Here, I've put in some title's to explain that:
color1 = uint8([100 150 200]);
color2 = uint8([180 50 250]);
rows = 480;
columns = 640;
redChannel = color1(1) * ones(rows, columns, 'uint8');
greenChannel = color1(2) * ones(rows, columns, 'uint8');
blueChannel = color1(3) * ones(rows, columns, 'uint8');
% Get/assign triangle vertices, triangleX, triangleY.
% I'm sure you can figure out what goes here!
triangleX = [0 100 200];
triangleY = [0 200 0];
% Create mask.
mask = poly2mask(triangleX, triangleY, rows, columns);
% Display mask
subplot(1,2,1);
imshow(mask);
title('This is the mask poly2mask made', 'FontSize', 25);
% Assign values to triangle defined by "mask" image.
redChannel(mask) = color2(1);
greenChannel(mask) = color2(2);
blueChannel(mask) = color2(3);
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
subplot(1,2,2);
imshow(rgbImage);
title('This is your triangle', 'FontSize', 25);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
If you want, you can just get rid of the first subplot() and imshow(). This solves your problem, so go ahead and mark it "Accepted."
Cesar
2013 年 2 月 15 日
I ran it and the triangle image is colored in 1 color...purple but not 2. The triangle must be colored in 2 colors.
Cesar
2013 年 2 月 15 日
The goal is to create 1 triangle (height 200, base 200) with 2 colors, not 2 triangles with 2 different colors.
Image Analyst
2013 年 2 月 15 日
編集済み: Image Analyst
2013 年 2 月 15 日
That was not the original question. It didn't mention two triangles, only two colors, assumed to be triangle and background colors. But the modification is really obvious. Just run the lines of code again, with different values of triangleX and triangleY.
Cesar
2013 年 2 月 15 日
I do not want 2 triangles. I need 1 triangle with 2 colors. If you run patch([0 100 200], [0 200 0], [1 0 0]) it shows 1 triangle with 1 color. I need that same size triangle with 2 colors.
Walter Roberson
2013 年 2 月 15 日
My reading of the question is one triangle in one color, plus the background in a different color, total two colors.
Cesar
2013 年 2 月 15 日
Sorry. The triangle image must be in 2 colors. Each side of the triangle must be in 1 color....by example 1 side red and 1 side green.
Image Analyst
2013 年 2 月 15 日
編集済み: Image Analyst
2013 年 2 月 15 日
I agree with Walter. Though if you need one triangle with two colors, and the background being a third color, then that can really be two triangles, each with a different color, stuck together, right? Is that what you want? Imagine a triangle, then draw a line from any vertex to a size, bisecting the triangle into two triangles. Ok, so now we're back to two triangles of a single color each and you can use my code. If that's still not what you want you'll have to upload a picture somewhere of exactly what you want (mock something up in Photoshop if you have to), because we're wasting a lot of time doing your homework for you and getting nowhere.
Cesar
2013 年 2 月 15 日
My question is simple. Half of the triangle in 1 color, the other half in another color. Since the base must be 200 pixels, 0 to 100 pixels in 1 color and 101 to 200 in a different color.
Image Analyst
2013 年 2 月 15 日
Fine. You can do it in one image. Show me the image you'd like to get. Post your URL with your desired image.
Image Analyst
2013 年 2 月 15 日
Yep. Looks like two tirangles to me. What's your opinion Walter? Could this be made by running my single triangle code twice with different vertex coordinates? Cesar, I can't ethically do your complete homework assignment for you. As it is, I practically did it for you. I don't want you to be caught plagiarizing. So exactly what are you asking of me? What code were you, or are you, expecting me to provide to you?
Cesar
2013 年 2 月 15 日
That's fine if you can not do it. You did not solve it by any means. I was just asking a question.
Image Analyst
2013 年 2 月 15 日
Ha ha! That's right - I cannot do it. It's way beyond my skill set. Perhaps I need to re-enroll in graduate school.
Walter Roberson
2013 年 2 月 15 日
Definitely looks like two triangles to me. Look at the shadows at the bottom: the one on the left is overlaying the one on the right, and one of the two is tilted with respect to the other.
Walter Roberson
2013 年 2 月 15 日
Cesar, you need to look more carefully at the image you supplied. Zoom in on the area near the tip. You will notice a few things:
- There appear to be three tips. The left tip is white, the center tip is white, the right tip is dark.
- The dark tip is part of a dark line that is most easily explained as if the dark line is the shadow of the center tip with respect to a light source that is to the left of center of the image.
- If the left (white) tip and center (white) tip were at equal heights, then both would have shadows, but there is only one shadow
- The details of the edge crossings of the left and center tips strongly suggest the interpretation that the left triangle is on top of the right triangle, with the left triangle ending a small bit to the right of the right triangle.
- the bottom line of the triangles show that the triangles continue to be overlapped all the way down
Together these make clear that this is not one bi-colored triangle: this is two triangles with no vertices in common.
Cesar
2013 年 2 月 16 日
I need 1 triangular image with height of 200 pixels and the base of 200 pixels colored with any two colors. Please read the description. Do not focus on the picture I sent. You either can solve it or not.
Walter Roberson
2013 年 2 月 16 日
If doing step (A) accomplishes half of a task, then doing step (A) twice, with different parameters each time, might accomplish the entire task.
Image Analyst
2013 年 2 月 16 日
編集済み: Image Analyst
2013 年 2 月 16 日
Well I think I will not solve it (supposedly I don't know how). I did way too much already, and it's such a trivial chore to finish it. Like Walter and I said, just do it twice. You said that half the triangle was one color and the other half was a different color. Now, ask yourself "What shape is half a triangle?" But ultimately it's your problem, not ours, and we should not do 100% of it for you, and I won't. There needs to be some part of it that you own, that you write yourself. You have all the tools, so, good luck with that.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)