function imlin = imagetolinear(imnon)

%% imlin = imagetolinear(imnon)
%%
%% This function accepts as input an [n x m x 3] image matrix of nonlinear RGB
%% values, performs the conversion to linearRGB for each pixel, and returns
%% an image of linearized RGB values.
%%
%% created: JSB 6/13/00

[n m p] = size(imnon);

imlin = zeros(n,m,3);
rgbrow_non = zeros(3,m);
rgbrow_lin = zeros(3,m);

for i = 1:n
	for j = 1:m
		rgbrow_non(1,j) = imnon(i,j,1);
		rgbrow_non(2,j) = imnon(i,j,2);
		rgbrow_non(3,j) = imnon(i,j,3);
	end
	rgbrow_lin = tolinear(rgbrow_non);
	for j = 1:m
		imlin(i,j,1) = rgbrow_lin(1,j);
		imlin(i,j,2) = rgbrow_lin(2,j);
		imlin(i,j,3) = rgbrow_lin(3,j);
	end
end




