generating random particles effect to an image
이전 댓글 표시
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?
채택된 답변
추가 답변 (1개)
Image Analyst
2022년 8월 6일
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.

카테고리
도움말 센터 및 File Exchange에서 Modify Image Colors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




