- the circle perimeter alone,
- the part inside the circle, or
- the part outside the circle.
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to remove few part of a circle?
조회 수: 1 (최근 30일)
이전 댓글 표시
Zara Khan
2019년 3월 2일
I am drawing different radius circles over an image object using simple plot function. How can remove circle portion from background and will only left the portion that is going through image object.
답변 (1개)
Image Analyst
2019년 3월 2일
You can make a mask and then use it to erase the part of the image you don't want
binaryImage(mask) = false; % Erase in mask
However your wording is so ambiguous, I don't know what the mask should be :
Please explain better or attach a desired output image.
댓글 수: 17
Image Analyst
2019년 3월 3일
Assuming when you generate each circle, you have the (x,y) coordinates of it, simply erase them:
for k = 1 : length(x)
col = round(x);
row = round(y);
binaryImage(row, col) = false;
end
Zara Khan
2019년 3월 3일
clc;
close all;
clear;
workspace;
a = imread('img.png');
bwimg =bwareafilt(~a, 1);
s=regionprops(bwimg,'Orientation','Centroid','MajorAxisLength','MinorAxisLength');
circleCenterX =s.Centroid(1);
circleCenterY =s.Centroid(2);
diameter = mean([s.MajorAxisLength s.MinorAxisLength],2);
figure;
imshow(bwimg);
set (gca,'TickLabelInterpreter','none');
set(gca,'fontweight','bold','fontsize',12);
set(gca,'color','black');
get(0,'Factory');
hold on
for n=1:8
r=n*diameter/16;
t=0:0.001:2*pi;
x = circleCenterX + r* sin(t);
y = circleCenterY + r * cos(t);
plot(x,y, 'LineWidth', 2);
for k=1:length(x);
col=round(x);
row=round(y);
bwimg(row,col)=false;
end
end
This is not working .
Image Analyst
2019년 3월 14일
Yes, try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
rgbImage = imread('img.png');
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(rgbImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = rgbImage(:, :, 2); % Take green channel.
else
grayImage = rgbImage; % It's already gray scale.
end
% Now it's definitely gray scale with range of 0 to 255.
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
binaryImage = bwareafilt(~grayImage, 1);
props = regionprops(binaryImage,'Orientation','Centroid','MajorAxisLength','MinorAxisLength');
circleCenterX = props.Centroid(1);
circleCenterY = props.Centroid(2);
% Get the average of the min and max diameter.
diameter = mean([props.MajorAxisLength, props.MinorAxisLength], 2)
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
hold on
drawnow;
circumference = 2 * pi * props.MajorAxisLength;
t = linspace(0, 2*pi, 1.5 * circumference);
fprintf('Writing black to the %d points along the circles.', length(t));
for n = 1 : 8
fprintf('Processing circle #%d.\n', n);
r = n * diameter / 16;
x = circleCenterX + r * sin(t);
y = circleCenterY + r * cos(t);
plot(x,y, 'LineWidth', 2);
% Make the binary image black where it is at the circle.
for k=1:length(x)
col=round(x(k));
row=round(y(k));
binaryImage(row,col) = false;
end
end
% Display the final image.
subplot(2, 2, 3);
imshow(binaryImage);
title('Final Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');

Zara Khan
2019년 3월 15일
Image Analyst:
Thank you for your effort sir. But I have tried to show how will be my desired output by adding the "i.png" where all circle permiters are in black colors. But actually it will be in colors.Only the portion where its getting background will be ommited just like your final image. But here all are perimeters are in black. Is this possible to make them colors?
Image Analyst
2019년 3월 15일
Sure, just change it to an RGB image.
rgbImage(row,col, 1) = redColor;
rgbImage(row,col, 2) = greenColor;
rgbImage(row,col, 3) = blueColor;
Of course you will need to change those values every circle if you want different colors. They should be in the range 0-255.
Image Analyst
2019년 10월 24일
Not sure what you mean. The code above will work for any color, just put in the right values.
Zara Khan
2019년 10월 29일
% Make the binary image black where it is at the circle.
for k=1:length(x)
col=round(x(k));
row=round(y(k));
binaryImage(row,col) = false;
end
end
I want to change this portion .
% Make the binary image black where it is at the circle.
I want to make the binary image to any colour where it is at the circle. I am using colour code but its not working .
After making this I want to chane the image black background to white keeping the image circle portion intact .
Image Analyst
2019년 10월 29일
Binary images are only black or white. You can use an RGB image though:
rgbImage(row,col, 1) = redValue;
rgbImage(row,col, 2) = greenValue;
rgbImage(row,col, 3) = blueValue;
Zara Khan
2019년 10월 31일
for k=1:length(x)
col=round(x(k));
row=round(y(k));
binaryImage(row,col) = false;
How to change the false to any other colour?
Zara Khan
2019년 11월 4일
How can make the black background to white ,keeping circle portion instead ? Changing the black background to white making full image white.
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)