Photoshop filter: contrast, luminance, fun!
December 22, 2008 5:57 AM Subscribe
I want to calculate the average contrast, luminance and any other interesting photo statistics (things that might be useful/important in psychophysics) for a bunch of images. I've heard that both Matlab and Photoshop can do this. I'm still trying to avoid learning Matlab, so Photoshop is preferred (I tried google, and some image manipulation books I found in the library, but neither were very helpful).
What I'm looking to do in the end is to create a noise image based on the average contrast/luminance/etc of my original images. If someone knows a way of doing that, I'd love you forever!
What I'm looking to do in the end is to create a noise image based on the average contrast/luminance/etc of my original images. If someone knows a way of doing that, I'd love you forever!
NIH Image is another option to consider. I haven't used it in years, but when I needed to do something vaguely similar it was a hugely helpful.
posted by exogenous at 9:32 AM on December 22, 2008
posted by exogenous at 9:32 AM on December 22, 2008
If I understand correctly, what you want is to calculate appropriate means and standard deviations from your image, either directly or after some conversion to select appropriate information, and then generate (gaussian?) noise from that.
It may not be user-friendly enough for your purposes but, as is usual in image-related questions, ImageMagick may be able to help you. Check out fx expressions.
posted by ghost of a past number at 11:02 AM on December 22, 2008
It may not be user-friendly enough for your purposes but, as is usual in image-related questions, ImageMagick may be able to help you. Check out fx expressions.
posted by ghost of a past number at 11:02 AM on December 22, 2008
If you're going to be doing this sort of thing a lot, it's definitely worth learning Matlab. I use it all the time for these sorts of things, and if you have the image processing toolbox, it makes a lot of image analysis very quick and easy. Since images are just arrays of numbers and Matlab is very good at array processing it's a good tool for the job, though you could do the calculations in any package you like, really.
That said, your question is not entirely clear to me. It sounds like you want to calculate some statistical properties of your images (mean and standard deviation? entropy?) and then calculate a random image with those same statistical properties?
Also, NIH-Image has been succeeded by ImageJ
posted by pombe at 11:26 AM on December 22, 2008
That said, your question is not entirely clear to me. It sounds like you want to calculate some statistical properties of your images (mean and standard deviation? entropy?) and then calculate a random image with those same statistical properties?
Also, NIH-Image has been succeeded by ImageJ
posted by pombe at 11:26 AM on December 22, 2008
Response by poster: @handee, pombe & ghost of a past number.
I want to calculate the mean and standard deviation for a number of image statistics, including luminance and contrast, so I can make sure that they do not differ between my images.
What I want to do then is create a gaussian noise image from these means and standard deviations, so that my noise image does not differ statistically from my actual images.
I need to stop posting these questions at midnight!
Thanks to all for your suggestions so far.
posted by doctor.dan at 1:36 PM on December 22, 2008
I want to calculate the mean and standard deviation for a number of image statistics, including luminance and contrast, so I can make sure that they do not differ between my images.
What I want to do then is create a gaussian noise image from these means and standard deviations, so that my noise image does not differ statistically from my actual images.
I need to stop posting these questions at midnight!
Thanks to all for your suggestions so far.
posted by doctor.dan at 1:36 PM on December 22, 2008
Best answer: I would make an average histogram from your data images and construct a new noise image based on the average histogram.
You don't want to use Photoshop for this. I would use PIL, as kcm suggested, but matlab should work as well.
This would not be Gaussian noise, but I'm not sure what you mean by creating a Gaussian noise image from a mean contrast value. A histogram will capture all the non-local information about the image.
posted by demiurge at 3:05 PM on December 22, 2008
You don't want to use Photoshop for this. I would use PIL, as kcm suggested, but matlab should work as well.
This would not be Gaussian noise, but I'm not sure what you mean by creating a Gaussian noise image from a mean contrast value. A histogram will capture all the non-local information about the image.
posted by demiurge at 3:05 PM on December 22, 2008
Doing this in matlab is easy if you know what you want to do and you have the image processing toolbox (you have not answered my last question yet - do you have matlab and the image processing toolbox? browsing your past questions suggests you probably do... but I'm not going to be arsed to write you example code unless you confirm that!!)
and learning matlab, as a post-doc in computer vision, has increased my productivity 2 or 3 fold so I'd not delay that step if it's something that could be useful to you,,,
posted by handee at 4:20 PM on December 22, 2008
and learning matlab, as a post-doc in computer vision, has increased my productivity 2 or 3 fold so I'd not delay that step if it's something that could be useful to you,,,
posted by handee at 4:20 PM on December 22, 2008
Response by poster: @ demiurge, thanks for your answer.
@ handee, sorry about that. Yes, I do have Matlab and am installing the image processing toolbox now. I'll have a play with it, but would love example code if its not too much trouble (don't go nuts on my behalf).
posted by doctor.dan at 5:51 PM on December 22, 2008
@ handee, sorry about that. Yes, I do have Matlab and am installing the image processing toolbox now. I'll have a play with it, but would love example code if its not too much trouble (don't go nuts on my behalf).
posted by doctor.dan at 5:51 PM on December 22, 2008
Best answer: OK quick and dirty here... and it just does the mean image.. but along with a matlab book and a bit of imagination you should be able to get it to do what you want. Quite often I find when starting with a new programming language/environment it's the boring stuff that's hard (how do you open an image? how do you view your results? how do you store things in an array?) so I've commented it a bit and it should get you over those first hurdles. Copy and paste into a file called mean_image.m, then invoke it from the matlab command prompt. Look out for the "if you're on windows" comment!!
function [difference_images,mi]=mean_image(directory_path, varargin)
% Takes a directory name and bunch of strings which refer to
% image files, and returns the mean image and a cell array
% containing difference images
% example: output=mean_image('/tmp/','file1.png','file2.png')
%
% to view the output difference_images do
% imagesc(difference_images{1});
% imagesc(difference_images{2});
% etc.
%
% if the images are different sizes, it's gonna do something
% unpredictable. you could add a sanity check if you want
% find how many image files there are:
optargin=size(varargin,2);
%get the first file
% if you're on windows, switch the slash between %s and %s to a \
filename=sprintf('%s/%s',directory_path,varargin{1});
disp('reading first image file');
disp(filename);
im=imread(filename);
% set the mean image to be the first image
mi=im;
for (i=2:optargin) %start @ 2 as we've already done 1
filename=sprintf('%s/%s',directory_path,varargin{1});
disp('reading image file');
disp(filename);
im=imread(filename);
%add the current image to the mean image
mi=mi+im;
% if you want to accumulate other statistics, just
% alter the line above to accumulate whatever you
% want to do - for intensity, you could turn
% the image greyscale using rgb2gray then do the
% accumulation...
end
%divide the mean image by the total number of images to get
%the average
mi=mi./optargin;
% now we go through again calculating the different images
for (i=1:optargin)
filename=sprintf('%s/%s',directory_path,varargin{i});
disp('reading image file again');
disp(filename);
im=imread(filename);
difference_images{i}=im-mi;
end
posted by handee at 3:34 AM on December 23, 2008 [1 favorite]
function [difference_images,mi]=mean_image(directory_path, varargin)
% Takes a directory name and bunch of strings which refer to
% image files, and returns the mean image and a cell array
% containing difference images
% example: output=mean_image('/tmp/','file1.png','file2.png')
%
% to view the output difference_images do
% imagesc(difference_images{1});
% imagesc(difference_images{2});
% etc.
%
% if the images are different sizes, it's gonna do something
% unpredictable. you could add a sanity check if you want
% find how many image files there are:
optargin=size(varargin,2);
%get the first file
% if you're on windows, switch the slash between %s and %s to a \
filename=sprintf('%s/%s',directory_path,varargin{1});
disp('reading first image file');
disp(filename);
im=imread(filename);
% set the mean image to be the first image
mi=im;
for (i=2:optargin) %start @ 2 as we've already done 1
filename=sprintf('%s/%s',directory_path,varargin{1});
disp('reading image file');
disp(filename);
im=imread(filename);
%add the current image to the mean image
mi=mi+im;
% if you want to accumulate other statistics, just
% alter the line above to accumulate whatever you
% want to do - for intensity, you could turn
% the image greyscale using rgb2gray then do the
% accumulation...
end
%divide the mean image by the total number of images to get
%the average
mi=mi./optargin;
% now we go through again calculating the different images
for (i=1:optargin)
filename=sprintf('%s/%s',directory_path,varargin{i});
disp('reading image file again');
disp(filename);
im=imread(filename);
difference_images{i}=im-mi;
end
posted by handee at 3:34 AM on December 23, 2008 [1 favorite]
This thread is closed to new comments.
And by "noise image" do you mean an average image (so will your contrast be different at different places in the input image)?
My understanding of what you want is an average image for each metric, then this can create a noise image comprising of the difference between the average for each metric and the individual input images on that metric, with each metric being something like brightness, sharpness, whatever. This is easy in matlab, but you're going to have to work out what you want your metrics to be!
You can do a lot with just average images: towards the bottom of the page here is a demonstration of averaging over the Caltech101 dataset, and here is a demo of average faces.
And one last question: do you have the Matlab image procesing toolbox?
posted by handee at 6:33 AM on December 22, 2008