median of a sequence of images operating pixel-by-pixel

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
jmaroza

median of a sequence of images operating pixel-by-pixel

Post by jmaroza »

Hi,

I have been (unsuccesfully) searching for a script to compute an image as the median of a rather large sequence of images, operating pixel-by-pixel. That is, every resulting pixel should be (in graylevel or luminance or any other 1-dimensional measure) the median of pixels in te same position along the sequence.

Does anybody know how to do it?

Thanks in advance,

José.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: median of a sequence of images operating pixel-by-pixel

Post by fmw42 »

Post a suggestion to the Developers forum to add median as an option to -evaluate-sequence, which can already do mean, min, max for each pixel over a sequence of images. Standard Deviation might also be useful
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: median of a sequence of images operating pixel-by-pixel

Post by GreenKoopa »

With a smallish, fixed number of images, or with a large or varying number of images?

Say your 1-dimensional measure was graylevel. Do you want your resulting image to be those graylevel values, or the color values that gave those graylevel measures? The former MAY be easier, and definitely would not be more difficult.

fmw42, is there a usage example using -evaluate-sequence, or a list of operator is may use?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: median of a sequence of images operating pixel-by-pixel

Post by fmw42 »

fmw42, is there a usage example using -evaluate-sequence, or a list of operator is may use?
Presumably it can use most if not all of the -evaluate operators (convert -list evaluate). But I cannot be sure which ones actually make sense for such. All I know about are min,max,mean.

see the original discussion at viewtopic.php?f=1&t=15711&hilit=evaluate+sequence

orginally there was one -average which has now been deprecated by -evaluate sequence

note that min and max could be done using -compose lighten/darken -composite

Example

convert image1 image2 image3 ... imageN -evaluate-sequence mean result_mean_image
jmaroza

Re: median of a sequence of images operating pixel-by-pixel

Post by jmaroza »

GreenKoopa wrote:With a smallish, fixed number of images, or with a large or varying number of images?

Say your 1-dimensional measure was graylevel. Do you want your resulting image to be those graylevel values, or the color values that gave those graylevel measures? The former MAY be easier, and definitely would not be more difficult.

fmw42, is there a usage example using -evaluate-sequence, or a list of operator is may use?
Thanks to fmw42 and GreenKoopa for posting. What I need is to get the median image of a rather great number of them, may be up to 400 images, all 640x480.

-evaluate-sequence permits arithmetic and logical expressions to be evaluated pixel-by-pixel, but I have no idea on how to evaluate (640x480 times) the median of a series of 400 graylevels. Probably the task is far from being trivial, since it requires ordering 400 graylevels, pixel-by-pixel.

I'll suggest to developers to create the option, although I suspect that they have already thought on it, but it is not so easy.

Thanks to all,

José.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: median of a sequence of images operating pixel-by-pixel

Post by fmw42 »

Perhaps I misunderstood. I thought you wanted one resulting image of size 640x480 which had the median value at each pixel computed from 400 images. That is pixel 0,0 in the result is the median of pixel 0,0 from all of the 400 images, etc for each pixel location within the 640x480 coordinates. Is that not what you want?

Do you want the median of each image, then the median of all the medians?
jmaroza

Re: median of a sequence of images operating pixel-by-pixel

Post by jmaroza »

fmw42 wrote:Perhaps I misunderstood. I thought you wanted one resulting image of size 640x480 which had the median value at each pixel computed from 400 images. That is pixel 0,0 in the result is the median of pixel 0,0 from all of the 400 images, etc for each pixel location within the 640x480 coordinates. Is that not what you want?

Do you want the median of each image, then the median of all the medians?
Sorry for not explaining clearly and for my bad English. Yes, it is just what I need, fmw42. Pixel 0,0 of resulting image must be the median of pixel 0,0 from all the 400 images, an so on with remaining pixels. Since original images are coloured, a 1-dimensional measure must be taken, such as graylevel, or luminance, or chanel, or whatever.

An example of my work can be seen in http://aljayani.ujaen.es. It is a 24-hour webcam of the sky. It generates an image every minute. Due to the luminic contamination of the city, stars are dificult to see. However, if we substract from every image a model of the sky specific to the current time, then lots os stars appear, as well as the Milky Way. An example is shown by clicking on "Videogaleria", then in "La Via Lactea" (sorry, the web page is for didactic purposes and it is only in Spanish). The video has been created almost by hand. Every photogram is the difference of the original image and the model of the sky. The model is just the median of all original images in the range [-200minutes,+200minutes] with respect to the time of the original image. The result is spectacular. We would like to automatize this process and offer processed videos in the web.

I posted to developers. My post has been readed, but still no response.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: median of a sequence of images operating pixel-by-pixel

Post by magick »

Install ImageMagick, version 6.6.6, and try -evaluate-sequence median.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: median of a sequence of images operating pixel-by-pixel

Post by anthony »

The address http://aljayani.ujaen.es/ errors.
PHP Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in C:\Inetpub\wwwroot\index.php on line 8
PHP Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in C:\Inetpub\wwwroot\index.php on line 17
PHP Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in C:\Inetpub\wwwroot\index.php on line 30
PHP Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in C:\Inetpub\wwwroot\planisferio.php on line 208

I would love to see these 'webcam stars'. I have taken photos of the night sky using long exposures (not really very long) on a digital camera from my backyard.

Original image from camera (very dark)
http://www.ict.griffith.edu.au/~anthony ... ht_sky.jpg

After some simple contrast enhancement (Greens became too bold but it basically worked)

Code: Select all

  convert night_sky.jpg -strip -resize 800x600 \
          -sigmoidal-contrast 15,0% night_sky_enhanced.jpg
Image
Yes the house is my neighbour! And yes that is the southern cross near the top, as I do live in the land 'Down Under'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jmaroza

Re: median of a sequence of images operating pixel-by-pixel

Post by jmaroza »

magick wrote:Install ImageMagick, version 6.6.6, and try -evaluate-sequence median.
With Imagemagick 6.6.6-0 2010-11-21 Q16:

...> convert *.jpg -evaluate-sequence median out.jpg

Magick: unrecognized evaluate operator `median' @ error/convert.c/ConvertImageCommand/1388
jmaroza

Re: median of a sequence of images operating pixel-by-pixel

Post by jmaroza »

anthony wrote:The address http://aljayani.ujaen.es/ errors.
PHP Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in C:\Inetpub\wwwroot\index.php on line 8
PHP Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in C:\Inetpub\wwwroot\index.php on line 17
PHP Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in C:\Inetpub\wwwroot\index.php on line 30
PHP Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in C:\Inetpub\wwwroot\planisferio.php on line 208
Nice photo!

Unexpected error. No user had reported it before. I'll try to debug. Please try again. I have put an "@" before gethostbyaddress to avoid strange messages.
jmaroza

Re: median of a sequence of images operating pixel-by-pixel

Post by jmaroza »

I've seen a new version 6.6.6-1 including support for -evaluate-sequence median. Thanks to developers for being so diligent!.

Unfortunately, downloaded pack ImageMagick-6.6.6-1-Q16-windows-dll.exe still has a convert.exe reporting 6.6.6-0 version. Am I doing something wrong?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: median of a sequence of images operating pixel-by-pixel

Post by magick »

Version 6.6.6-0 supports the -evaluate-sequence median as well. Give it a try.
jmaroza

Re: median of a sequence of images operating pixel-by-pixel

Post by jmaroza »

magick wrote:Version 6.6.6-0 supports the -evaluate-sequence median as well. Give it a try.
$magick>convert *.jpg -evaluate-sequence median out.jpg

Magick: unrecognized evaluate operator `median' @ error/convert.c/ConvertImageCommand/1388

Perhaps I'm doing something wrong?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: median of a sequence of images operating pixel-by-pixel

Post by magick »

Ok, we'll need to build ImageMagick 6.6.6-1 for Windows and release it. We'll need a few days.
Post Reply