trying to make a donut mask to span over images, suggestions?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
[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 Kommentare
Akzeptierte Antwort
Kevin Holly
am 23 Feb. 2023
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 Kommentare
Kevin Holly
am 24 Feb. 2023
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)
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!