Notifications
Clear all

[Closed] Exposure control with maxscript. Is it possible?

The problem is shown in the images below.
I know that 3ds max is not a photo editing software, but it is possible, only with maxscript, to be created tools like Exposure control in Photoshop.
I know that VFB+ by lo have this option, but I think that he uses dotNet for this.

25 Replies

[i]Exposure control with maxscript. Is it possible?

[/i]everything is possible. but using just maxscript the tool will work very slow. you can use mxs+dotnet and LockBits method, but it will need a lot of memory. so the complied c# assembly (on-the-fly is OK) is the right way to do it.

c#
I know only the name of this programing language.

I suppose that the script have to process every pixel of the image, and when the image is 8000x4000px this is…:sad:

that will be processed very slow, or it will need an array 8000×4000 which will take a lot of memory

3 Replies
 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

80004000RGBA = 128mb
I don’t think it’s such a large amount of memory for editing a 32MP image.
If memory is critical, it can be split into several blocks of lockbits.

(@feranti)
Joined: 11 months ago

Posts: 0

It seems that the images are HDR (32 bits per channels) so:
80004000 (32+32+32+32) = 4096 Mb = 512 MB of RAM

I think…

 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

Yes, though if you’re talking about dotnet they would be clamped to 8bits. But yes, 128mb for 8bit, 512mb for 32bit float.

I will try with maxscript, but can’t find the formula or formulas of exposure.
Found only this:

%
% Implementation of Exposure Fusion
%
% written by Tom Mertens, Hasselt University, August 2007
% e-mail: tom.mertens@gmail.com
%
% This work is described in
%   "Exposure Fusion"
%   Tom Mertens, Jan Kautz and Frank Van Reeth
%   In Proceedings of Pacific Graphics 2007
%
%
% Usage:
%   result = exposure_fusion(I,m);
%   Arguments:
%	 'I': represents a stack of N color images (at double
%	   precision). Dimensions are (height x width x 3 x N).
%	 'm': 3-tuple that controls the per-pixel measures. The elements 
%	 control contrast, saturation and well-exposedness, respectively.
%
% Example:
%   'figure; imshow(exposure_fusion(I, [0 0 1]);'
%   This displays the fusion of the images in 'I' using only the well-exposedness
%   measure
%

function R = exposure_fusion(I,m)

r = size(I,1);
c = size(I,2);
N = size(I,4);

W = ones(r,c,N);

%compute the measures and combines them into a weight map
contrast_parm = m(1);
sat_parm = m(2);
wexp_parm = m(3);

if (contrast_parm > 0)
	W = W.*contrast(I).^contrast_parm;
end
if (sat_parm > 0)
	W = W.*saturation(I).^sat_parm;
end
if (wexp_parm > 0)
	W = W.*well_exposedness(I).^wexp_parm;
end

%normalize weights: make sure that weights sum to one for each pixel
W = W + 1e-12; %avoids division by zero
W = W./repmat(sum(W,3),[1 1 N]);

% create empty pyramid
pyr = gaussian_pyramid(zeros(r,c,3));
nlev = length(pyr);

% multiresolution blending
for i = 1:N
	% construct pyramid from each input image
	pyrW = gaussian_pyramid(W(:,:,i));
	pyrI = laplacian_pyramid(I(:,:,:,i));
	
	% blend
	for l = 1:nlev
		w = repmat(pyrW{l},[1 1 3]);
		pyr{l} = pyr{l} + w.*pyrI{l};
	end
end

% reconstruct
R = reconstruct_laplacian_pyramid(pyr);



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% contrast measure
function C = contrast(I)
h = [0 1 0; 1 -4 1; 0 1 0]; % laplacian filter
N = size(I,4);
C = zeros(size(I,1),size(I,2),N);
for i = 1:N
	mono = rgb2gray(I(:,:,:,i));
	C(:,:,i) = abs(imfilter(mono,h,'replicate'));
end

% saturation measure
function C = saturation(I)
N = size(I,4);
C = zeros(size(I,1),size(I,2),N);
for i = 1:N
	% saturation is computed as the standard deviation of the color channels
	R = I(:,:,1,i);
	G = I(:,:,2,i);
	B = I(:,:,3,i);
	mu = (R + G + B)/3;
	C(:,:,i) = sqrt(((R - mu).^2 + (G - mu).^2 + (B - mu).^2)/3);
end

% well-exposedness measure
function C = well_exposedness(I)
sig = .2;
N = size(I,4);
C = zeros(size(I,1),size(I,2),N);
for i = 1:N
	R = exp(-.5*(I(:,:,1,i) - .5).^2/sig.^2);
	G = exp(-.5*(I(:,:,2,i) - .5).^2/sig.^2);
	B = exp(-.5*(I(:,:,3,i) - .5).^2/sig.^2);
	C(:,:,i) = R.*G.*B;
end

Wow! What is that. You right when you say:“I know only name of this programing language”:hmm:

I think that this is written in C. There are formulas for converting RGB values, but I have to check the C syntax to understand how to convert this to maxscript. And then I will know if this is the right formula or not.

Actually Richard Annema created a simple exposure render effect that shipped as part of the Bonus Tools with Brazil 2. If you can find a copy of Brazil 2 Rio, you could look through his exposure/blur/vignette tools to see how it was done.

-Eric

Send u a mail

 lo1

For only exposure the formula is quite simple:

multiply each R,G,B value by 2^X, where X is the exposure value.

You will not get very far in pure maxscript, certainly not realtime performance.
An on-the-fly c# assembly will get you at acceptable performance, but C++ code will still be faster.

EDIT: Looking again at your post, dotnet or c# will not help you here at all, as GDI+ only deals with 8bit images, and your example clearly shows HDR imagery. It’s either slow maxscript or SDK C++ in this case.

EDIT2: As a small aside, it is not correct that in c# you would need to iterate all the pixels to get the desired result. You can simply use the ColorMatrix class together with ImageAttributes class to adjust exposure (and also saturation, contrast, offset for the same price), but as I mentioned, this is only useful in 8-bit land.

Page 1 / 2