필터 지우기
필터 지우기

Change color from a circle form in an image

조회 수: 6 (최근 30일)
Cracan Irinel
Cracan Irinel 2023년 1월 4일
댓글: Image Analyst 2023년 1월 6일
Hello. I have to find circles in an image and to change their colors. I found the circles, but I don't know how to detect the color and change.

답변 (3개)

Luca Ferro
Luca Ferro 2023년 1월 6일
  댓글 수: 1
DGM
DGM 2023년 1월 6일
Regarding the latter topic, this answer also applies and includes links to several other demos on various means to change colors.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2023년 1월 6일
편집: Image Analyst 2023년 1월 6일
The color is the RGB values of the image array. Not sure what you mean by detect, but if you want a mask of certain colors, then try using the Color Thresholder on the Apps tab of the tool ribbon. Try HSV color space and click the button to export code.

DGM
DGM 2023년 1월 6일
편집: DGM 2023년 1월 6일
I'm just going to throw this out there as one idea. You could also pick colors in a region near the known center (if you can rely on the center being clear).
This uses MIMT tools, but the links include examples that don't use MIMT. The core idea here is just a means to find the colored regions by identifying the most common color within each circle. This isn't really a good approach generally, but for this case with broad regions of uniform color.
% so you have an RGB image
inpict = imread('circlecircle.png');
inpict = im2double(inpict); % this is needed later
% say you already know where the circles are regardless of their color
C = [68 74; 134 115];
R = [51 58];
% create an indexed copy to simplify color picking
[indpict map] = rgb2ind(inpict,64);
% preallocate mask
ncircles = numel(R);
mask = false([size(indpict) ncircles]);
% sample those locations based on the circle geometry
imshow(inpict); % set up axes to use ROI tools
for b = 1:ncircles
% create mask
ROI = images.roi.Circle(gca);
ROI.Center = C(b,:);
ROI.Radius = R(b);
circmask = createMask(ROI);
% sample region in indexed copy
samplepx = indpict(circmask);
% find color of most common index
% integer-class indexed images index from zero
modecolor = map(mode(samplepx)+1,:)
modecolor = permute(modecolor,[1 3 2]);
% find all pixels in the ROI close to the most common color in the ROI
tol = 0.1; % pick some tolerance
thismask = all(abs(inpict-modecolor) <= tol,3) & circmask;
mask(:,:,b) = imclose(thismask,ones(3)); % fill in thin lines (optional)
end
% now you have masks for the colored region within each circle or partial circle
% you can use those in whatever way you choose
% alter the hue in each region
hueshift = rand(2,1); % amount to shift hue for each blob (random example)
outpict = inpict;
for b = 1:ncircles
% these are both from MIMT, but there are non-MIMT examples
modpict = imtweak(outpict,'hsl',[hueshift(b) 1 1]);
outpict = replacepixels(modpict,outpict,mask(:,:,b));
end
imshow(outpict)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by