trying to make a donut mask to span over images, suggestions?
조회 수: 4 (최근 30일)
이전 댓글 표시
[x,y] = meshgrid(1:width, 1:height);
centerX = (width + 1) / 2;
centerY = (height + 1) / 2;
dist = sqrt((x - centerX).^2 + (y - centerY).^2);
innerRadius = 50;
outerRadius = 100;
masksign = false(height, width);
masksign(dist >= innerRadius & dist <= outerRadius) = true;
masksign = grayImage >= lowThreshold & grayImage <= highThreshold;
imshow(masksign);
댓글 수: 0
채택된 답변
Kevin Holly
2023년 2월 23일
RGBImage = imread("peppers.png");
imshow(RGBImage)
size(RGBImage)
width = 300;
height = 300;
[x,y] = meshgrid(1:width, 1:height);
centerX = (width + 1) / 2;
centerY = (height + 1) / 2;
dist = sqrt((x - centerX).^2 + (y - centerY).^2);
innerRadius = 50;
outerRadius = 100;
masksign = false(height, width);
masksign(dist >= innerRadius & dist <= outerRadius) = true;
% masksign = grayImage >= lowThreshold & grayImage <= highThreshold;
figure
imshow(masksign);
size(masksign)
figure
imshow(uint8(masksign).*RGBImage(1:300,1:300,:))
댓글 수: 3
Kevin Holly
2023년 2월 24일
I am not sure what exactly you are trying to accomplish. Below, I rotated the images you create to show a half donut halved vertically.
width = 300;
height = 300;
% Create a meshgrid
[x,y] = meshgrid(1:width, 1:height);
% Set the center coordinates of the donut
centerX = (width + 1) / 2;
centerY = (height + 1) / 2;
% Calculate the distance of each point from the center
dist = sqrt((x - centerX).^2 + (y - centerY).^2);
% Set the radii of the inner and outer circles
innerRadius = 50;
outerRadius = 100;
% Create a logical array for the mask
masksign = false(height, width);
% Set the region between the radii to true
masksign(dist >= innerRadius & dist <= outerRadius) = true;
% Set the region above the center to false
masksign(1:round(centerY),:) = false;
% Display the mask
figure
imshow(masksign);
stacked_vertically = [];
% Define the number of half donut masks to create
numMasks = 9;
% Define the size of the image
width = 300;
height = 300;
% Calculate the width of each mask
maskWidth = floor(width / numMasks);
% Create a meshgrid
[x,y] = meshgrid(1:width, 1:height);
% Loop through each mask and create a half donut mask
for i = 1:numMasks
% Calculate the center coordinates of the mask
centerX = (maskWidth * (i - 0.5));
centerY = (height + 1) / 2;
% Calculate the distance of each point from the center
dist = sqrt((x - centerX).^2 + (y - centerY).^2);
% Set the radii of the inner and outer circles
innerRadius = 50;
outerRadius = 100;
% Create a logical array for the mask
% masksign = false(height, maskWidth);
% Set the region between the radii to true
masksign = dist >= innerRadius & dist <= outerRadius;
% Set the region above the center to false
masksign(1:round(centerY),:) = false;
% Display the mask
subplot(2,numMasks,i);
imshow(masksign);
% Display the mask
subplot(2,numMasks,i+numMasks);
imshow(imrotate(masksign,90));
stacked_vertically = [stacked_vertically ; imrotate(masksign,90)];
end
figure
imshow(stacked_vertically)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!