我目前正在研究一个函数,该函数模拟水中粒子的运动作为时间的函数。然而,我得到的图像具有非常波动的强度,如下所示:



编辑:
我正在写一个函数,使用函数"nfmie“生成一系列图像,显示粒子在水中的位置作为时间的函数。然而,生成的图像都具有不同的背景强度值(一些图像非常暗,一些图像是灰色的)。
我的问题是如何改变或重新调整这些图像的强度以保持恒定。当使用mean2计算每个图像的平均强度时,我得到的值从85到90。我想在生成图像之前调整强度,即在我的原始函数内,这样我就不需要在外部执行此操作。
下面是我的函数中创建电影的部分(图像是从这里拍摄的)
============================
function finalmiescatter
close all;
clear variables;
colormap('gray')
%======================================
tf_flag=true;
cc_flag=false;
dia=[750*2e-9]; % sphere diameter
rad=dia/2;
ns=[1.5]; % sphere refractive index (complex)
nm=1.333; % outer medium refractive index (real)
lambda=632.8e-9; % vaccuum wavelength here
conv=1;
k=2*pi/lambda*nm; % the wavenumber in medium nm
x=k*dia/2; % the size parameter
m=ns/nm; % the relativere fractive index
%======================================
%======================================
% produce movie here and some paramters
Nx=200;
Ny=200;
N=10;
f=5;
sf=10;
x0=[0,0,0];
v0=[0,0,-200e-9];
Lx=1e-5;
Ly=1e-5;
[x,y,z]=mytimeseries(N,f,dia,sf,x0,v0);
%======================================
tic
vidObj=avifile('movie.avi');
meanintensity=zeros(N,1);
for i=1:N
[nx,ny]=coordinates(Lx,Ly,Nx,Ny,[x(i),-y(i)]);
[xf,yf]=ndgrid(nx,ny);
zf=zeros(size(xf))+z(i);
% generate a frame here
[E,H]=nfmie(an,bn,xf,yf,zf,rad,ns,nm,lambda,tf_flag,cc_flag);
Ecc=sqrt(real(E(:,:,1)).^2+real(E(:,:,2)).^2+real(E(:,:,3)).^2+imag(E(:,:,1)).^2+imag(E(:,:,2)).^2+imag(E(:,:,3)).^2);
clf
meanintensity(i)= mean2(Ecc);
imagesc(nx/rad,ny/rad,Ecc);
rectangle('Position',[-dia(end),-dia(end),dia(end),dia(end)],'Curvature',[1,1]);
axis image;
axis off;
frame=getframe(gca);
cdata_size = size(frame.cdata); % Find the size of the current frame
% Create an empty array that is slightly larger than the current frame (in powers of 4 pixels)
data = uint8(zeros(ceil(cdata_size(1)/4)*4,ceil(cdata_size(2)/4)*4,3));
% "Zero-pad" the current frame by copying the current frame into the empty array
data(1:cdata_size(1),1:cdata_size(2),1:cdata_size(3)) = [frame.cdata];
frame.cdata = data; % Use the zero-padded array as the current image
vidObj = addframe(vidObj,frame);
end
vidObj = close(vidObj);
toc
return
title('$|\vec{E} \cdot \vec{E}^*|$','FontSize',18,'FontName','times','Interpreter','latex');
xlabel('$x/a$','FontSize',18,'FontName','times','Interpreter','latex');
ylabel('$y/a$','FontSize',18,'FontName','times','Interpreter','latex');
set(gca,'FontSize',18,'FontName','Times');
print -depsc e.eps
return
============
function [xp,yp] = coordinates(Lx,Ly,Nx,Ny,xpar)
% Returns coordinates relative to particle position in a spacified frame:
% Lx,Ly = the lab width/height of the frame (m)
% Nx/Ny = the number of pixel in the x and y directions (-)
% xpar a vector of the particle position coordinates [x,y,z]
x=linspace(0,Nx,Nx)*Lx/Nx-Lx/2;
y=linspace(0,Ny,Ny)*Ly/Ny-Ly/2;
xp=x-xpar(1);
yp=y-xpar(2);
return
===========
function [x,y,z]=mytimeseries(N,f,d,sf,x0,v0)
% Returns x y and z coordinates (m) given:
% N = number of frames
% f = frame rate (Hz)
% d = particle diameter
% sf = scale factor (-)
% x0 = initial position (m)
% v0 = drift velocity (m/s)
% Call: [x,y,z]=mytimeseries(1000,10,200e-9,0.5,[0 0 0],0.1e-6*[0 0 -1])
dt=1/f;
delta=d*dt;
x=zeros(N,1);
y=zeros(N,1);
z=zeros(N,1);
x(1)=x0(1);
y(1)=x0(2);
z(1)=x0(3);
for i=2:N
dx=delta*normrnd(0,1)+v0(1)*dt;
dy=delta*normrnd(0,1)+v0(2)*dt;
dz=delta*normrnd(0,1)+v0(3)*dt;
x(i)=x(i-1)+dx;
y(i)=y(i-1)+dy;
z(i)=z(i-1)+dz;
end
if 1==0
figure(1)
plot(x,'-bo'); hold on
plot(y,'-ro'); hold on
plot(z,'-go'); hold on
ylabel('position (m)')
xlabel('frame')
end
============================ 那么,有没有办法让这个函数生成的图像保持相同的亮度呢?提前谢谢你!硝基
发布于 2014-06-14 08:08:35
尝试标准化,使均值为0,方差为1。这是一种常见的技术,用于使强度图像不随照明变化而变化,前提是它们属于同一场景。如果你还记得概率论,这是通过获得Z分数来执行的:

回想一下,标准差就是方差的平方根。
下面是一些代码供您试用:
%// Downloaded the images you have provided and
%// converted to double.
im1 = im2double(imread('32oYz.png'));
im2 = im2double(imread('fGDKS.png'));
im3 = im2double(imread('GEsUI.png'));
%// Create normalized images
im1Norm = (im1 - mean(im1(:))) / std(im1(:));
im2Norm = (im2 - mean(im2(:))) / std(im2(:));
im3Norm = (im3 - mean(im3(:))) / std(im3(:));
%// Convert back to uint8
im1Norm = im2uint8(im1Norm);
im2Norm = im2uint8(im2Norm);
im3Norm = im2uint8(im3Norm);
%//Side by side comparison
%// Left column is the original
%// Right column is the processed image
figure;
subplot(3,2,1);
imshow(im1);
subplot(3,2,2);
imshow(im1Norm);
subplot(3,2,3);
imshow(im2);
subplot(3,2,4);
imshow(im2Norm);
subplot(3,2,5);
imshow(im3);
subplot(3,2,6);
imshow(im3Norm);这是我得到的数字:

底部的那个给我们带来了一些麻烦,因为在波纹的中心有一个巨大的强度峰值,这会扭曲我们的平均值和标准差计算。虽然这可能并不完美,但对于您来说,这是一件很好的事情。
祝好运!
https://stackoverflow.com/questions/24213717
复制相似问题