How do I make a different shape like a hexagon or triangle using image processing?

4 Ansichten (letzte 30 Tage)
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

Antworten (2)

Akira Agata
Akira Agata am 28 Nov. 2019
If you want to create regulay polygon shape image, how about using nsidedpoly function?
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)
hexagon.png

Image Analyst
Image Analyst am 27 Nov. 2019
  9 Kommentare
murat murat
murat murat am 24 Nov. 2021
I am using matlab 2014 so that is the problem, :.(
thank you very much
Image Analyst
Image Analyst am 24 Nov. 2021
Then just try getting rid of that option and see if it still works.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by