trying to make a donut mask to span over images, suggestions?

5 ビュー (過去 30 日間)
Neo
Neo 2023 年 2 月 23 日
コメント済み: Neo 2023 年 2 月 24 日
[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);

採用された回答

Kevin Holly
Kevin Holly 2023 年 2 月 23 日
RGBImage = imread("peppers.png");
imshow(RGBImage)
size(RGBImage)
ans = 1×3
384 512 3
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)
ans = 1×2
300 300
figure
imshow(uint8(masksign).*RGBImage(1:300,1:300,:))
  3 件のコメント
Kevin Holly
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)
Neo
Neo 2023 年 2 月 24 日
Hi Dr. @Kevin Holly Thank you for this it really helped.
I am trying to get my attached script to work.
My code is attempting to count the number of dots (using a left half donut shaped mask) over 12 (or 9 the number is arbitrary) consecutive locations evenly distributed across the image and plot the count of the content as a function of the location.
My issues are the integer values are either not logical, or not positive and my code doesn't like that. Everytime I think I fix it, some other related error pops up. I thought the issue was the mask, then the maxDistance but now i am unsure. What would you suggest? Thank you.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by