is it possible to add/paint multiple colors(more than 100 up to 10000) to an RGBA image in MATLAB?

1 Ansicht (letzte 30 Tage)
i need help with changing the colors of an attached RGBA image randomly or cutomized manner (atelast red, orange, yellow, green, blue, purple, pink, brown, gray, black and white). i am attaching a code created by @DGM for the single purple color. i would highly appreicate any help with the code for mutiple colors randomly or customized manner
[body,~,bodya] = imread('Body/maroon.png');
bodypurple = imtweak(body,'hsl',[-0.28 1 1]);
imshow(bodypurple)
imwrite(bodypurple,'purple.png','alpha',bodya)
  2 Kommentare
Benjamin Thompson
Benjamin Thompson am 13 Mär. 2022
You may need to be more specific about what you want and how your current work is not yet working. You can use randi to generate random integer numbers, or rand or randn for double precision random numbers. I can see there could be a problem assigning a unique and useful name to each one of 10,000 colors so how are you looking to do that?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

DGM
DGM am 13 Mär. 2022
Bearbeitet: DGM am 13 Mär. 2022
First off, a reminder that this is all using MIMT tools.
One way would be to do a simple hue rotation to create a series of modified images.
[body,~,bodya] = imread('everything/Body/maroon.png');
nhues = 10;
huestep = 1/nhues;
hues = 0:huestep:1-huestep;
for hk = 1:nhues
newbody = imtweak(body,'hsy',[hues(hk) 1 1]);
imwrite(newbody,sprintf('body_h%03d.png',round(hk*360)),'alpha',bodya)
end
You might even do multiple hue sweeps with different saturation or lightness factors
[body,~,bodya] = imread('everything/Body/maroon.png');
nhues = 10;
sats = [0.5 1 2];
huestep = 1/nhues;
hues = 0:huestep:1-huestep;
for sk = 1:numel(sats)
for hk = 1:nhues
newbody = imtweak(body,'hsy',[hues(hk) sats(sk) 1]);
imshow(newbody)
imwrite(newbody,sprintf('body_s%02d_h%03d.png',sk,round(hk*360)),'alpha',bodya)
end
end
For cases where you want to incorporate random colorization or colorization from a table, you might try doing a 'hue' or 'color' blend using imblend():
[body,~,bodya] = imread('everything/Body/maroon.png');
CT = parula(10); % a predefined or random color table
s0 = size(body);
for k = 1:size(CT,1)
cpict = colorpict(s0,CT(k,:));
newbody = imblend(cpict,body,1,'color');
imwrite(newbody,sprintf('body_CT%03d.png',k),'alpha',bodya)
end
... or using a random 10x3 color table
Note that using 'hue' or 'color' blends, even random ones, will tend to (roughly) preserve the lightness of the image regions. If you want something that is random and does not preserve anything, then you might try:
[body,~,bodya] = imread('everything/Body/maroon.png');
nframes = 10;
meshsize = 1; % try [1-4]
for k = 1:nframes
newbody = imblend(body,body,1,'bomb',meshsize);
imwrite(newbody,sprintf('body_bomb%03d.png',k),'alpha',bodya)
end
As the meshsize parameter increases above 1, you can expect to see reduced correlation between the colors in the various image regions. As the source image is flat-colored to begin with, the effects may not be as apparent as meshsize is increased. For meshsize > 1, you may see banding in the transition areas between color regions.
There's probably plenty of other options, but let's start with that.
  7 Kommentare
MS
MS am 14 Mär. 2022
Bearbeitet: MS am 14 Mär. 2022
@DGM Yes, thanks. It worked well. i like the hue/hue rotaion method for preserving the image quality than randomisation method. Thanks again.
DGM
DGM am 14 Mär. 2022
Yeah, the random 'bomb' blends can be pretty destructive to image continuity. That's kind of why I ended up naming them that way.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by