How do I make a different shape like a hexagon or triangle using image processing?
조회 수: 23 (최근 30일)
이전 댓글 표시
Hi, I have a Labtest in 2 hours and just found out that we need to know how to make different shapes such as a hexagon using image processing which I’m not familiar with. We were given this code which just makes a square. Any help would be appreciated.
layer_1 = 255*ones(50, 50);
layer_2 = 255*ones(50, 50);
layer_3 = 255*ones(50, 50);
my_image(:,:,1) = layer_1; % applied to 3D matrix. my_image(:,:,2) = layer_2; % applied to 3D matrix. my_image(:,:,3) = layer_3;
imshow(my_image);
for row_index = 1:25 for col_index = 25:50 my_image(row_index,col_index,1)= 0; my_image(row_index,col_index,3) = 0; end end
imshow(my_image);
My friend also gave me this code but it also makes a square. for i=1:100 for j=1:100 mat(j,i,1)=255; mat(j,i,2)=0; mat(j,i,3)=0; end end
imshow(mat)
Also pls bare my shitty editing skills, I’m not sure how to insert code since I’m using my iPad rn.
Thanks
if true
for i=1:100
for j=1:100
mat(j,i,1)=255;
mat(j,i,2)=0;
mat(j,i,3)=0;
end
end
imshow(mat)
end
if true
layer_1 = 255*ones(50, 50);
layer_2 = 255*ones(50, 50);
layer_3 = 255*ones(50, 50);
my_image(:,:,1) = layer_1; % applied to 3D matrix. my_image(:,:,2) = layer_2; % applied to 3D matrix. my_image(:,:,3) = layer_3;
imshow(my_image);
for row_index = 1:25 for col_index = 25:50 my_image(row_index,col_index,1)= 0; my_image(row_index,col_index,3) = 0; end end
imshow(my_image); end
댓글 수: 0
답변 (2개)
Akira Agata
2019년 11월 28일
The folloing is an example:
% Create hexagon polyshape
pgon = nsidedpoly(6,'Center',[50,50],'Radius',30);
% Generate 100x100 binary image with hexagon
[xGrid,yGrid] = meshgrid(1:100,1:100);
BW = isinterior(pgon,xGrid(:),yGrid(:));
BW = reshape(BW,size(xGrid));
% Visualize
figure
imshow(BW)
댓글 수: 1
HG
2021년 6월 9일
how can I create a triangle or rectangle with curve edge ? and then show the matrix with imagesc ?
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!