I want to create a 3D square prism image with a specified hole location but in my 3D image ,it is showing only the 3D image of a square prism. How can I do that?

3 views (last 30 days)
I have a code that I tried out but the result it gave me was a 3D square prism shape without the hole in it. Although I have coded a hole in the square image.Can someone guide me please? It is urgent for my thesis.
clc;
clear;
close all;
A = zeros(120,144) ;
[m,n] = size(A) ;
mx = m/2 ; my = n/2 ;
S = 100 ; % side of square
x = (mx-S/2):(mx+S/2) ;
y = (my-S/2):(my+S/2) ;
[X,Y] = meshgrid(round(x),round(y)) ;
idx = sub2ind(size(A),X(:),Y(:)) ;
A(idx) = 1 ;
imshow(A);
imageSizeX = 120;
imageSizeY = 144;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
centerX = 100;
centerY = 20;
radius = 4;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels) ;
colormap([0 0 0; 1 1 1 ]);
C = imfuse(A,circlePixels);
imshow(C);
fin_model = repmat(C,1,1,3);

Answers (0)

Community Treasure Hunt

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

Start Hunting!