GithubHelp home page GithubHelp logo

Comments (3)

Shrediquette avatar Shrediquette commented on May 29, 2024

This will wok:


clear all; clc;drawnow
selpath = uigetdir;
noise = 0; %noise 0 bis 0.05
z_move=0; %z_move
size=600; %image size x and y
partAm=20000;
Z=0.333; %sheet thickness
dt=4; %particle diameter
ddt=2; %particle diameter variation
disp(['Generating random artificial PIV images with ' num2str(partAm) ' particles...'])
for iiii = 0:99
disp(['Progress: ' int2str(iiii/99100) ' %']);
%% Generate random artificial particle images
u = zeros(size,size);
v=zeros(size,size);
offsety=v+0; %zero displacement in y direction
offsetx=u+iiii/10; %uniform x displacement increases from 0 to 99/10 pixels
[x,y]=meshgrid(1:1:size);
i=[];
j=[];
sizey=size;
sizex=size;
A=zeros(sizey,sizex);
B=A;
z0_pre=randn(partAm,1); %normal distributed sheet intensity
randn('state', sum(100
clock)); %#ok<RAND>
z1_pre=randn(partAm,1); %normal distributed sheet intensity
z0=z0_pre
(z_move/200+0.5)+z1_pre*(1-((z_move/200+0.5)));
z1=z1_pre*(z_move/200+0.5)+z0_pre*(1-((z_move/200+0.5)));

I0=255*exp(-(Z^2./(0.125*z0.^2))); %particle intensity
I0(I0>255)=255;
I0(I0<0)=0;

I1=255*exp(-(Z^2./(0.125*z1.^2))); %particle intensity
I1(I1>255)=255;
I1(I1<0)=0;

randn('state', sum(100*clock));
d=randn(partAm,1)/2; %particle diameter distribution
d=dt+d*ddt;
d(d<0)=0;
rand('state', sum(100*clock));
x0=rand(partAm,1)*sizex;
y0=rand(partAm,1)*sizey;
rd = -8.0 ./ d.^2;

xlimit1=floor(x0-d/2); %x min particle extent image1
xlimit2=ceil(x0+d/2); %x max particle extent image1
ylimit1=floor(y0-d/2); %y min particle extent image1
ylimit2=ceil(y0+d/2); %y max particle extent image1
xlimit2(xlimit2>sizex)=sizex;
xlimit1(xlimit1<1)=1;
ylimit2(ylimit2>sizey)=sizey;
ylimit1(ylimit1<1)=1;

%calculate particle extents for image2 (shifted image)
x0integer=round(x0);
x0integer(x0integer>sizex)=sizex;
x0integer(x0integer<1)=1;
y0integer=round(y0);
y0integer(y0integer>sizey)=sizey;
y0integer(y0integer<1)=1;

xlimit3=zeros(partAm,1);
xlimit4=xlimit3;
ylimit3=xlimit3;
ylimit4=xlimit3;
for n=1:partAm
	xlimit3(n,1)=floor(x0(n)-d(n)/2-offsetx((y0integer(n)),(x0integer(n)))); %x min particle extent image2
	xlimit4(n,1)=ceil(x0(n)+d(n)/2-offsetx((y0integer(n)),(x0integer(n)))); %x max particle extent image2
	ylimit3(n,1)=floor(y0(n)-d(n)/2-offsety((y0integer(n)),(x0integer(n)))); %y min particle extent image2
	ylimit4(n,1)=ceil(y0(n)+d(n)/2-offsety((y0integer(n)),(x0integer(n)))); %y max particle extent image2
end
xlimit3(xlimit3<1)=1;
xlimit4(xlimit4>sizex)=sizex;
ylimit3(ylimit3<1)=1;
ylimit4(ylimit4>sizey)=sizey;

ctr=0;
for n=1:partAm
	ctr=ctr+1;
	if ctr==10000
		ctr=0;
		%fprintf('.')
	end
	r = rd(n);
	for j=xlimit1(n):xlimit2(n)
		rj = (j-x0(n))^2;
		for i=ylimit1(n):ylimit2(n)
			A(i,j)=A(i,j)+I0(n)*exp((rj+(i-y0(n))^2)*r);
		end
	end
	for j=xlimit3(n):xlimit4(n)
		for i=ylimit3(n):ylimit4(n)
			B(i,j)=B(i,j)+I1(n)*exp((-(j-x0(n)+offsetx(i,j))^2-(i-y0(n)+offsety(i,j))^2)*-rd(n)); %place particle with gaussian intensity profile
		end
	end
end


%% Create random Background "glow"
bg=im2bw(rand(size,size),0.99999);
SE = strel('line',round(rand*90)+90,round(rand*180));
bg2=imdilate(bg,SE);
bg3 = imgaussfilt(double(bg2),40);
bg3=bg3/max(max(bg3));
bg3=bg3*0.1;
bg=im2bw(rand(size,size),0.999997);
SE = strel('disk',round(rand*100)+200,4);
bg2=imdilate(bg,SE);
bg4 = 0.12*imgaussfilt(double(bg2),100);
bg3(isnan(bg3))=0;
bg4(isnan(bg4))=0;

A=A+bg3*rand*255+bg4*rand*255;
B=B+bg3*rand*255+bg4*rand*255;

A(A>255)=255;
B(B>255)=255;
A=imnoise(uint8(A),'gaussian',0,noise);
B=imnoise(uint8(B),'gaussian',0,noise);

A=uint8(A);
B=uint8(B);

%True velocities, save if desired
x_real=x;
y_real=y;
u_real=u;
v_real=v;

imwrite(A,[selpath '\synth_image_' sprintf('%5.5d',iiii) '_A.jpg'],'Quality',97);
imwrite(B,[selpath '\synth_image_' sprintf('%5.5d',iiii) '_B.jpg'],'Quality',97);

end

from pivlab.

Shrediquette avatar Shrediquette commented on May 29, 2024

... but code formatting is broken in this github website

from pivlab.

WangJieHHU avatar WangJieHHU commented on May 29, 2024

This will work:
`clear all; clc;drawnow
selpath = uigetdir;
noise = 0; %noise 0 bis 0.05
z_move=0; %z_move
size=600; %image size x and y
partAm=20000;
Z=0.333; %sheet thickness
dt=4; %particle diameter
ddt=2; %particle diameter variation
disp(['Generating random artificial PIV images with ' num2str(partAm) ' particles...'])
for iiii = 0:99
disp(['Progress: ' int2str(iiii/99_100) ' %']); %% Generate random artificial particle images u = zeros(size,size); v=zeros(size,size); offsety=v+0; %zero displacement in y direction offsetx=u+iiii/10; %uniform x displacement increases from 0 to 99/10 pixels [x,y]=meshgrid(1:1:size); i=[]; j=[]; sizey=size; sizex=size; A=zeros(sizey,sizex); B=A; z0_pre=randn(partAm,1); %normal distributed sheet intensity randn('state', sum(100_clock)); %#ok<RAND> z1_pre=randn(partAm,1); %normal distributed sheet intensity z0=z0_pre(z_move/200+0.5)+z1_pre*(1-((z_move/200+0.5)));
z1=z1_pre*(z_move/200+0.5)+z0_pre*(1-((z_move/200+0.5)));

I0=255*exp(-(Z^2./(0.125*z0.^2))); %particle intensity
I0(I0>255)=255;
I0(I0<0)=0;

I1=255*exp(-(Z^2./(0.125*z1.^2))); %particle intensity
I1(I1>255)=255;
I1(I1<0)=0;

randn('state', sum(100*clock));
d=randn(partAm,1)/2; %particle diameter distribution
d=dt+d*ddt;
d(d<0)=0;
rand('state', sum(100*clock));
x0=rand(partAm,1)*sizex;
y0=rand(partAm,1)*sizey;
rd = -8.0 ./ d.^2;

xlimit1=floor(x0-d/2); %x min particle extent image1
xlimit2=ceil(x0+d/2); %x max particle extent image1
ylimit1=floor(y0-d/2); %y min particle extent image1
ylimit2=ceil(y0+d/2); %y max particle extent image1
xlimit2(xlimit2>sizex)=sizex;
xlimit1(xlimit1<1)=1;
ylimit2(ylimit2>sizey)=sizey;
ylimit1(ylimit1<1)=1;

%calculate particle extents for image2 (shifted image)
x0integer=round(x0);
x0integer(x0integer>sizex)=sizex;
x0integer(x0integer<1)=1;
y0integer=round(y0);
y0integer(y0integer>sizey)=sizey;
y0integer(y0integer<1)=1;

xlimit3=zeros(partAm,1);
xlimit4=xlimit3;
ylimit3=xlimit3;
ylimit4=xlimit3;
for n=1:partAm
	xlimit3(n,1)=floor(x0(n)-d(n)/2-offsetx((y0integer(n)),(x0integer(n)))); %x min particle extent image2
	xlimit4(n,1)=ceil(x0(n)+d(n)/2-offsetx((y0integer(n)),(x0integer(n)))); %x max particle extent image2
	ylimit3(n,1)=floor(y0(n)-d(n)/2-offsety((y0integer(n)),(x0integer(n)))); %y min particle extent image2
	ylimit4(n,1)=ceil(y0(n)+d(n)/2-offsety((y0integer(n)),(x0integer(n)))); %y max particle extent image2
end
xlimit3(xlimit3<1)=1;
xlimit4(xlimit4>sizex)=sizex;
ylimit3(ylimit3<1)=1;
ylimit4(ylimit4>sizey)=sizey;

ctr=0;
for n=1:partAm
	ctr=ctr+1;
	if ctr==10000
		ctr=0;
		%fprintf('.')
	end
	r = rd(n);
	for j=xlimit1(n):xlimit2(n)
		rj = (j-x0(n))^2;
		for i=ylimit1(n):ylimit2(n)
			A(i,j)=A(i,j)+I0(n)*exp((rj+(i-y0(n))^2)*r);
		end
	end
	for j=xlimit3(n):xlimit4(n)
		for i=ylimit3(n):ylimit4(n)
			B(i,j)=B(i,j)+I1(n)*exp((-(j-x0(n)+offsetx(i,j))^2-(i-y0(n)+offsety(i,j))^2)*-rd(n)); %place particle with gaussian intensity profile
		end
	end
end


%% Create random Background "glow"
bg=im2bw(rand(size,size),0.99999);
SE = strel('line',round(rand*90)+90,round(rand*180));
bg2=imdilate(bg,SE);
bg3 = imgaussfilt(double(bg2),40);
bg3=bg3/max(max(bg3));
bg3=bg3*0.1;
bg=im2bw(rand(size,size),0.999997);
SE = strel('disk',round(rand*100)+200,4);
bg2=imdilate(bg,SE);
bg4 = 0.12*imgaussfilt(double(bg2),100);
bg3(isnan(bg3))=0;
bg4(isnan(bg4))=0;

A=A+bg3*rand*255+bg4*rand*255;
B=B+bg3*rand*255+bg4*rand*255;

A(A>255)=255;
B(B>255)=255;
A=imnoise(uint8(A),'gaussian',0,noise);
B=imnoise(uint8(B),'gaussian',0,noise);

A=uint8(A);
B=uint8(B);

%True velocities, save if desired
x_real=x;
y_real=y;
u_real=u;
v_real=v;

imwrite(A,[selpath '\synth_image_' sprintf('%5.5d',iiii) '_A.jpg'],'Quality',97);
imwrite(B,[selpath '\synth_image_' sprintf('%5.5d',iiii) '_B.jpg'],'Quality',97);

end
`

Thank u!I‘m going to try it!

from pivlab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.