Filter löschen
Filter löschen

Change color from a circle form in an image

9 Ansichten (letzte 30 Tage)
Cracan Irinel
Cracan Irinel am 4 Jan. 2023
Kommentiert: Image Analyst am 6 Jan. 2023
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.

Antworten (3)

Luca Ferro
Luca Ferro am 6 Jan. 2023
  1 Kommentar
DGM
DGM am 6 Jan. 2023
Regarding the latter topic, this answer also applies and includes links to several other demos on various means to change colors.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 6 Jan. 2023
Bearbeitet: Image Analyst am 6 Jan. 2023
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 am 6 Jan. 2023
Bearbeitet: DGM am 6 Jan. 2023
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)

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by