generating random particles effect to an image
Afficher commentaires plus anciens
Hi!
I want to implement a code that generates random colored particles effect into an image, something like the attached image
'particles.jpg' . (the background will be bleck, eventually I want to create png image)
My idea is to generate random 2d gaussians (with random centers and radius), and then combining them to one image. After that I want to paint them with random colors (each of them will have different color).
can you please help me create this code?
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 6 Août 2022
Here's a start. I trust you can finish it. If so, see this:
% Demo by Image Analyst to create multiple Gaussians.
% Initialization Steps.
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;
numSpheres = 50;
windowWidth = 30;
rows = 640;
columns = 640;
grayImage = zeros(rows, columns, 'uint8');
for k = 1 : numSpheres
radius = windowWidth * rand;
g = rescale(fspecial("gaussian", windowWidth, radius), 0, 1);
g = uint8(255 * g);
subplot(1, 2, 1);
imshow(g, []);
axis('on', 'image')
caption = sprintf('One Gaussian with sigma = %.5f', radius);
title(caption, 'FontSize', fontSize)
xUpperLeft = round(rand(1) * (columns - windowWidth)) + 1;
yUpperLeft = round(rand(1) * (rows - windowWidth)) + 1;
% Paste in image
grayImage(yUpperLeft : (yUpperLeft + windowWidth - 1), xUpperLeft : (xUpperLeft + windowWidth - 1)) = g;
subplot(1, 2, 2);
imshow(grayImage, []);
axis('on', 'image')
caption = sprintf('%d Gaussians', k);
title(caption, 'FontSize', fontSize)
drawnow;
end
g = gcf;
g.WindowState = 'maximized'

I'm attaching another demo, gaussianCircles_demo.m, that produces this image.

Catégories
En savoir plus sur Modify Image Colors dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




