# how can i detect triangle

82 views (last 30 days)
how can i detect green colour triangle from pic

Muhammad Usman Saleem on 12 Jun 2016
is this image?
yes

Image Analyst on 12 Jun 2016
You can segment out that green triangle using either color or shape - your choice. I'm attaching demos for each. Feel free to adapt as needed.

i use this coding but it detect square ,.. plz help how can i detect triangle using this coding
clear all
clc
subplot(2,2,1)
imshow(Img) % RGB Image
subplot(2,2,2)
[Height Width]=size(Img(:,:,2));
for i=1:Height
for j=1:Width
if Img(i,j,1:2)<115
Triangle(i,j)=Img(i,j);
else Triangle(i,j)=256;
end end end
imshow(Triangle) % Detected Triangle
Image Analyst on 13 Jun 2016
Don't use for loops and simply vectorize it. Get rid of the size() and two for loops and simply have this:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Get pixels that are greener than they are red or blue.
Triangle = greenChannel > redChannel & greenChannel > blueChannel;
thanks sir

Muhammad Usman Saleem on 12 Jun 2016

#### 1 Comment

i use this coding but it detect square ,.. plz help how can i detect triangle using this coding
clear all
clc
subplot(2,2,1)
imshow(Img) % RGB Image
subplot(2,2,2)
[Height Width]=size(Img(:,:,2));
for i=1:Height
for j=1:Width
if Img(i,j,1:2)<115
Triangle(i,j)=Img(i,j);
else Triangle(i,j)=256;
end end end
imshow(Triangle) % Detected Triangle