comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Calculate median of stacks of images using IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Calculate median of stacks of images using IDL [message #88707] Fri, 06 June 2014 13:46 Go to next message
oatty3931 is currently offline  oatty3931
Messages: 8
Registered: June 2014
Junior Member
Hi,
I am trying to compute a median of a stack of images in TIF format for my research. From another source I found out a way to compute this from stack of images present in a GDF format, using

IDL> buf=read_gdf('demo.gdf')
IDL> help, buf
BUF FLOAT = Array[640, 480, 100]
IDL>b=median(buf,/double,dimension=3)

However, I am having difficulty converting my TIF images into GDF, but still need to normalize my images somehow. Any suggestions on how to do so?
Thank you in advance. Any help will be highly appreciated!
Nitsorn Wongsajjathiti
Re: Calculate median of stacks of images using IDL [message #88708 is a reply to message #88707] Sat, 07 June 2014 15:42 Go to previous messageGo to next message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
On Friday, June 6, 2014 4:46:37 PM UTC-4, Nitsorn Wongsajjathiti wrote:
> Hi,
>
> I am trying to compute a median of a stack of images in TIF format for my research. From another source I found out a way to compute this from stack of images present in a GDF format, using
>
>
>
> IDL> buf=read_gdf('demo.gdf')
>
> IDL> help, buf
>
> BUF FLOAT = Array[640, 480, 100]
>
> IDL>b=median(buf,/double,dimension=3)
>
>
>
> However, I am having difficulty converting my TIF images into GDF, but still need to normalize my images somehow. Any suggestions on how to do so?
>
> Thank you in advance. Any help will be highly appreciated!
>
> Nitsorn Wongsajjathiti

Hi Again,

You can use READ_IMAGE to read in your images, then stack them up, and take the median.

filenames = file_search("my_filename_regex*.tif")
buf = []
for f in filenames do $
buf = [[[buf]], [[read_image(f)]]]

b = median(buf, /double, dimension=3)

TTFN,

David
Re: Calculate median of stacks of images using IDL [message #88709 is a reply to message #88707] Sun, 08 June 2014 12:06 Go to previous messageGo to next message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
On Friday, June 6, 2014 3:46:37 PM UTC-5, Nitsorn Wongsajjathiti wrote:
> Hi,
>
> I am trying to compute a median of a stack of images in TIF format for my research. From another source I found out a way to compute this from stack of images present in a GDF format, using
>
>
>
> IDL> buf=read_gdf('demo.gdf')
>

So, I suppose READ_GDF is from another library, yes? Do you _need_ things in GDF?

If you have TIFFs, you can just use READ_TIFF, and create a 3d array like David suggests.

Depending on how many TIFFs you have, you may find this modification to David's snippet to be slightly more efficient:

filenames = file_search("my_filename_regex*.tif", COUNT=fileCount) ;get the filenames, and how many

isGood = QUERY_TIFF(filenames[0], tiffInfo) ;get information about the first TIFF file

;assuming the TIFFs are 8 bit....if 16bit you can change to UINTARR
buf = BYTARR([tiffInfo.resolution, fileCount]) ;assuming all TIFFs are the same size, preallocate the array

FOREACH f in filenames DO $
buf[0, 0, i] = READ_TIFF(f) ;read each TIFF into the buf array

b = median(buf, /double, dimension=3)
Re: Calculate median of stacks of images using IDL [message #88710 is a reply to message #88708] Mon, 09 June 2014 04:18 Go to previous messageGo to next message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
On Saturday, June 7, 2014 6:42:04 PM UTC-4, David Grier wrote:
> On Friday, June 6, 2014 4:46:37 PM UTC-4, Nitsorn Wongsajjathiti wrote:
>
>> Hi,
>
>>
>
>> I am trying to compute a median of a stack of images in TIF format for my research. From another source I found out a way to compute this from stack of images present in a GDF format, using
>
>>
>
>>
>
>>
>
>> IDL> buf=read_gdf('demo.gdf')
>
>>
>
>> IDL> help, buf
>
>>
>
>> BUF FLOAT = Array[640, 480, 100]
>
>>
>
>> IDL>b=median(buf,/double,dimension=3)
>
>>
>
>>
>
>>
>
>> However, I am having difficulty converting my TIF images into GDF, but still need to normalize my images somehow. Any suggestions on how to do so?
>
>>
>
>> Thank you in advance. Any help will be highly appreciated!
>
>>
>
>> Nitsorn Wongsajjathiti
>
>
>
> Hi Again,
>
>
>
> You can use READ_IMAGE to read in your images, then stack them up, and take the median.
>
>
>
> filenames = file_search("my_filename_regex*.tif")
>
> buf = []
>
> for f in filenames do $
>
> buf = [[[buf]], [[read_image(f)]]]
>
>
>
> b = median(buf, /double, dimension=3)
>
>
>
> TTFN,
>
>
>
> David

I was trying to avoid having to figure out the dimensions of the images. Here's a more general version:

buf = list()
for f in file_search("mynames*.tif") do $
buf.add, read_image(f)
b = median(buf.toarray(), /double, dimension=1)

This works for grayscale and color images, regardless of the pixel ordering.

TTFN,

David
Re: Calculate median of stacks of images using IDL [message #88712 is a reply to message #88707] Mon, 09 June 2014 12:01 Go to previous messageGo to next message
oatty3931 is currently offline  oatty3931
Messages: 8
Registered: June 2014
Junior Member
Thank you Prof. David and Phillip for your replies.
@Prof. David, I tried using both of your codes, and received an error. I completely understand how it works but due to my inefficiency in IDL, I am receiving a syntax error at:

IDL> buf=list()
IDL> for f in file_search("mynames*.tif") do $
> buf.add read_image(f)

for f in file_search("mynames*.tif") do $
^
% Syntax error.

Any help with this error? I apologize once again if this is a stupid function. I will be more careful with my questions next time.
Thank you in advance,
Nitsorn
Re: Calculate median of stacks of images using IDL [message #88713 is a reply to message #88707] Mon, 09 June 2014 12:16 Go to previous messageGo to next message
oatty3931 is currently offline  oatty3931
Messages: 8
Registered: June 2014
Junior Member
Thank you Prof. David and Phillip for your replies.
@Prof. David, I tried using both of your codes, and received an error. I completely understand how it works but due to my inefficiency in IDL, I am receiving a syntax error at:

IDL> buf=list()
IDL> for f in file_search("frame-*.tif") do $ ;my tif files in the working directory are labelled "frame-1.tif", "frame-2.tif" etc..
> buf.add read_image(f)

for f in file_search("mynames*.tif") do $
^
% Syntax error.

Any help with this error? I apologize once again if this is a stupid function. I will be more careful with my questions next time.
Thank you in advance,
Nitsorn
Re: Calculate median of stacks of images using IDL [message #88724 is a reply to message #88712] Tue, 10 June 2014 08:12 Go to previous messageGo to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 6/9/14, 1:01 PM, oatty3931@gmail.com wrote:
> Thank you Prof. David and Phillip for your replies.
> @Prof. David, I tried using both of your codes, and received an error. I completely understand how it works but due to my inefficiency in IDL, I am receiving a syntax error at:
>
> IDL> buf=list()
> IDL> for f in file_search("mynames*.tif") do $
>> buf.add read_image(f)
>
> for f in file_search("mynames*.tif") do $
> ^
> % Syntax error.
>
> Any help with this error? I apologize once again if this is a stupid function. I will be more careful with my questions next time.
> Thank you in advance,
> Nitsorn
>

Too much Python. Should be:

for f, file_search('mynames*.tif') do $

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
Re: Calculate median of stacks of images using IDL [message #88726 is a reply to message #88724] Tue, 10 June 2014 09:18 Go to previous messageGo to next message
oatty3931 is currently offline  oatty3931
Messages: 8
Registered: June 2014
Junior Member
Hi Mike,
Thank you for your reply. Unfortunately, I still received an error after:

IDL> buf=list()
IDL> for f, file_search("mynames*.tif") do $
> buf.add,read_image(f)

for f, file_search("mynames*.tif") do $
^
% Syntax error.

I am using IDL 8.2.3, if that helps
Thank you once again,
Nitsorn
Re: Calculate median of stacks of images using IDL [message #88727 is a reply to message #88726] Tue, 10 June 2014 09:36 Go to previous messageGo to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 6/10/14, 10:18 AM, oatty3931@gmail.com wrote:
> Hi Mike,
> Thank you for your reply. Unfortunately, I still received an error after:
>
> IDL> buf=list()
> IDL> for f, file_search("mynames*.tif") do $
>> buf.add,read_image(f)
>
> for f, file_search("mynames*.tif") do $
> ^
> % Syntax error.
>
> I am using IDL 8.2.3, if that helps
> Thank you once again,
> Nitsorn
>

Sorry, still too much Python:

foreach f, file_search('mynames*.tif') do $

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
Re: Calculate median of stacks of images using IDL [message #88728 is a reply to message #88727] Tue, 10 June 2014 09:51 Go to previous messageGo to next message
oatty3931 is currently offline  oatty3931
Messages: 8
Registered: June 2014
Junior Member
Thank you! That works perfectly :)
Re: Calculate median of stacks of images using IDL [message #88742 is a reply to message #88728] Wed, 11 June 2014 11:21 Go to previous message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
On Tuesday, June 10, 2014 12:51:38 PM UTC-4, oatt...@gmail.com wrote:
> Thank you! That works perfectly :)

Egads! As Mike points out, I've been doing too much python programming recently.
I'm very sorry for the crumpled code example!

Sigh,

David
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to use SPAWN for creating multiple output files?
Next Topic: IDLdoc 3.6.0 released

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:27:07 PDT 2025

Total time taken to generate the page: 0.00513 seconds