I do most of my software development these days using Python under Windows. I had the idea of rewriting my DICOM PHP class in Python with the mind of ease of use under Windows and including any needed DCMTK binaries in a nice package. From past experience with other languages I knew it could be difficult to start other programs in the background on Windows and then keep track of them. I set out to write a simple store and forward application using Python and the DCMTK to see what I was getting myself into.

Turns out Python has some really nice modules for running programs in the background. In a very short period of time I had the beginnings of pretty slick DICOM application. Even as a quick and dirty test application it is able to:

  • Read DICOM tags from files.
  • Start promiscuous DICOM storage services on port 4343
  • Write any images it receives into a directory.
  • Watch that directory for files and detect if those files are DICOM.
  • Compress DICOM files, using a compress type suitable to the file’s modality
  • Send DICOM files to a remote host
  • Perform a DICOM ping in order to tell if a DICOM host is up

You can download all of my files here. Just extract the zip, the good stuff is in snf.py. Take note that this is just proof of an idea and by no means safe or production worthy code.

If you don’t feel like downloading it, here is the complete source:

import subprocess
import time
import os  
import xml.etree.ElementTree as ET

# Is the file a DICOM file?
def is_dcm(file):
  f = os.popen('dcmtk/bin/dcm2xml.exe ' + file)
  out = f.read()
  if not "TransferSyntaxUID" in out:
    return False
  return True

def echoscu(host, port):
  f = os.popen('dcmtk/bin/echoscu.exe ' + host + ' ' + port)
  out = f.read()
  if not out:
    return True
  return False

# Dump out the DICOM header into an array indexed by the tag tags['0010,0010'] = some value
def dcm_dump(file):
  # Run dcm2xml to get some XML of the DICOM headers
  f = os.popen('dcmtk/bin/dcm2xml.exe ' + file)
  out = f.read()
  root = ET.fromstring(out)

  # The XML we get doesn't make it easy to look up tags. Lets reorganize it
  tags = {}

  # Get the meta tags  
  for child in root:
    tag = child.tag
    value = child.attrib['name']
    name = child.attrib['name']
    tags[tag] = value 

  # Get the real tags
  for child in root.iter('element'):
    tag = child.attrib['tag']
    value = child.text
    name = child.attrib['name']
    tags[tag] = value

  return tags

# pull the value from the array generated by dcm_dump()
def get_tag(tags, tag):
  try:
    tags[tag]
  except:
    return ''
  
  val = tags[tag]
  return val

def storescu_switch(ts):
  if 'JPEG Baseline' in ts:
    return '-xy'
  elif 'JPEG Extended' in ts:
    return '-xx'
  elif 'JPEG Lossless' in ts:
    return '-xs';
  else:
    return ''

  

# Compress a DICOM file if need be
def compress_dcm(modality, ts, file):
  switch = ''
  new_ts = ''
  if not 'JPEG' in ts: # we need to compress
    tmp_file = 'temp.dcm'
    
    if modality == 'US':
      switch = '+eb'
      new_ts = 'JPEG Baseline'
    elif modality == 'CR' or modality == 'DR' or modality == 'DX' or modality == 'SC' or modality == 'RG' or modality == 'OT':
      swtich = '+ee'
      ts = 'JPEG Extended'
    else:
      switch = ''
      new_ts = 'JPEG Lossless'

    f = os.popen('dcmtk/bin/dcmcjpeg.exe ' + switch + ' ' + file + ' ' + tmp_file)
    out = f.read()
    if(out):
      print out
      new_ts = ''
    else:
      os.remove(file)
      os.rename(tmp_file, file)
    
  if(new_ts):
    ts = new_ts
  return ts

# Send a DICOM file, compress if needed
def send_dcm(file):
  print file
  tags = dcm_dump(file)
  
  ts = compress_dcm(get_tag(tags, '0008,0060'), get_tag(tags, 'data-set'), file)
  
  switch = storescu_switch(ts)
  my_ae = 'PYTHON'
  remote_ae = 'DEANO'
  host = '192.168.1.216'
  port = '105'

  print ts
  print switch

  f = os.popen('dcmtk/bin/storescu.exe -ta 10 -td 10 -to 10 ' + switch + ' -aet ' + my_ae + ' -aec ' + remote_ae + ' ' + host + ' ' + port + ' ' + file)
  out = f.read()
  
  print out
  if not out:
    os.remove(file)
    print file + " sent OK"
  
# Program flow
# Start storescp
# Loop through temp_images directory
# Detect dicom file
# Figure out if compressed
# If not, compress based on modality
# Send File in another thread
# Send OK: Delete File
# Check on storescp... echoscu myself... if no good for five tries... kill and restart storescp

# Directories and defines
base_dir = "C:\\rrad\\r"
temp_images = base_dir + '\\temp_images'

listen_port = '4343' # Hopefully always free

# Start storescp
storescp_args = "-dhl -td 20 -ta 20 -xf " + base_dir + "\\storescp.cfg Default -od " + temp_images + ' ' + listen_port
subprocess.Popen("dcmtk/bin/storescp.exe " + storescp_args)


x = 0 # count runs
bad_echoscus = 0 # Count failed echoscus

# Main loop
while True:
#  print temp_images + " : " + storescp_args + "\n"
  print "Run: ", x

  # check out the temp_images dir for DICOM files
  for fn in os.listdir(temp_images):
    if is_dcm(temp_images + '\\' + fn):
      send_dcm(temp_images + '\\' + fn) # Found one, send it
    else:
      os.remove(temp_images + '\\' + fn)
      print "Removed non-DICOM file: " + fn

  # Every 5 runs, echoscu myself   
  if x == 5:
    if echoscu('localhost', '4343'):
      print "ECHOSCU OK"
      bad_echoscus = 0
    else:
      print 'Echoscu NG'
      bad_echoscus += 1

    x = 0
    if bad_echoscus == 3:
      print "Too many bad echoscus"

  x += 1 
  time.sleep(5);

Crabby Wallet

The Crabby Wallet was one of the first Kickstarter wallets around. It managed to get $300,000 over its original pledge request of $10,000. Typically such a large amount over the original request spells death for a Kickstarter, but the folks behind Crabby managed to pull it all together and deliver the wallets pretty much on time.

I received my Crabby Wallet about a week ago and immediately put it to use as my day to day wallet, replacing a Ridge Wallet.

The first thing you notice is that the Crabby Wallet isn’t the prettiest girl at the dance. It’s black elastic with an elastic strap that comes in a few different colors. Going purely by looks I would pick my Ridge Wallet any day. The second thing you notice about the Crabby Wallet is that it’s small and thin, oh so very thin. The crabby is slightly longer but slightly shorter than a credit card. Cards in the top slot stick out a bit. This makes it very easy to put cards in and take them out, at the same time an elastic strap holds them in so there is no danger of them falling out. With four credit cards inside the Crabby Wallet is roughly the same thickness as a Ridge Wallet empty. It is by far the slimmest Wallet I’ve owned.

The Crabby Wallet solves my one complaint with The Ridge, pocket feel. The Ridge is smooth aluminum, it would slide around my pocket and end up at odd angles. Sometimes my key fob would get involved and sit on the wallet making it very uncomfortable. The Crabby Wallet is made out of elastic, it doesn’t slide around in my pocket. Its thin enough that if my key fob does sit on top of the wallet its not a big deal.

For the ease of use and comfort that comes with the Crabby Wallet I can get over any problems I have with its looks. I really like the Crabby Wallet and it will be the wallet I use for a long time.

You  can buy a Crabby Wallet from http://www.crabbygear.com/

2013-12-16 Update: The elastic began to wear quite a bit and fray. On a recent trip I was pulling cards in and out of the wallet seemingly constantly and it just about did the little guy in. As it is now, the wallet still looks alright, no holes or anything glaring. The elastic band is noticeably frayed. The wallet is very loose. If I dropped it I think the contents would spill out.

It’s the first wallet I have ever worn out and it only took a few months. It’s sad because I really like it.

 

The first and only Nintendo 3DS flash cart was released last month. Here is my take on it.

It works, mostly. You can put a Nintendo 3DS ROM on an SD card and play it via the Gateway cart. If you’re used to DS flash cartridges and their features you’re going to be in for some surprises though.

As of this writing the Gateway 3DS only works on firmware 4.5. If you’ve ever updated your 3ds you’re out of luck for now.

The Gateway 3DS only allows one rom per SD card. The SD card does not need to be the exact size of the ROM.

The Gateway 3DS does not run any homebrew yet. That means no emulators for SNES, GBA, ect.

The Gateway 3DS does not run DS games. You need a DS flash cart like the DSTWO for that.

The biggest problem is that games that utilize saves do not save once you take the cartridge out. Chew on the implications of that for a bit.

Sadly, that’s a whole lot of ‘does nots.’ Good news is that the makers of the Gateway have plans to resolve all of these problems in future firmware updates as the cartridge is upgradable.

In the meantime the Gateway 3DS is more of a proof of concept than a real usable flash cartridge.

 

Galaxy S3 with Game Klip

I like playing old games. I missed out on the NDS, Game Boy Color, GBA, and the butt end of the SNES and Genesis. Playing games from those consoles is actually something new for me.

I’ve known about old console emulation on Android phones for a long time. I had an original Droid phone that ran NES games alright. Having to use the touch screen as a controller though makes playing the games frustrating. I’ve played around a bit with using a Wiimote as a controller but then you have to prop up the phone somehow so you can have both hands free to hold the controller, no fun either.

Jump cut to the GameKlip. The GameKlip is a bracket that fits around a PS3 Dual Shock 3 controller and attaches to your Android phone or tablet. You get a real controller to use with your games and you don’t have to try to balance your phone on your lap. The GameKlip is a great idea and I can’t say enough good things about it.

I currently have a Samsung Galaxy S3 running the stock android ROM that came with it. I have attempted to use other ROMs such at CyanogenMod and Slim Bean but they would cause the game emulators to crash after a bit of play. Very cause and effect. Flawless under the stock ROM, reboot into CyanogenMod, load the same quick save up, play for a few minutes, emulator locks up. Bummer.

How well does the Galaxy S3 emulate the different consoles?

PSX: Great! Surprising considering how other emulators perform. Using RetroArch.

N64: It’s hit and miss. Some games wont even load. Speed can be an issue. Mario Kart is sort of playable. Slower paced games like Ogre Battle work ok. I’m currently using MuPen64 Plus AE. I’ve tried several other emulators and its the best all things considered. If you mix and match emulators most anything will at least load. Playability not so much.

SNES: It works well. There can be slow downs in spots with lots of sprites moving around (Contra 3), but nothing that ruins it for you. I’m using SNES9x EX+

Genesis: The same as the SNES.

NDS: Works great. Trying to show both of the DS screens at once on the little S3 screen just makes me wish I had an Android tablet to run the emulators on. Using DrasStic.

GBA: Perfect. No complaints at all. I’m using My Boy!.

GBC/Gameboy: Perfect. I’m using GBC.emu.

NES: Perfect. I’m using John NES Lite.

What about sound lag?

I’ve read a lot about Android emulators having bad sound lag. For instance, you grab a coin in Mario and you don’t hear the sound for it until a second later. Judging from the amount of reports on the Internet I’ve seen it must be a real problem. I already had an Android phone and most of the emulators have free to try versions. I didn’t have any risk involved in trying it out. If I had to buy a phone (or even one of the Android handheld consoles or a tablet) and then hope that emulation works, I wouldn’t have done it. That’s how worrisome all of the lag reports are.

Luckily though I have not had any problems with sound lag in my setup. Is it just my phone? Maybe my combination of emulators, ROM, and Android version is good? Dunno. It just works right for me as is.

What about RetroArch?

Why use all of these other emulators? RetroArch is free and emulates every system!

RetroArch is a good concept. All of the emulators in one place, no questions about licenses, and free. Good times.

RetroArch is hit or miss though. For instance, PSX emulation under it is near perfect. GBC emulation suffers from horrible slow downs and choppy sound. Considering the specs of the two systems you would expect the opposite problem. Using different emulators tailored to a specific system works well for me.  I may have spent $15 total for all of them, but I get a lot of value back in return.

 

I have a Nintendo 3dS XL. I wanted to get a DSTWO flash cart to run emulators. While researching what to buy I couldn’t find a straight answer on how well the emulation works, specifically for SNES and GBA. About the one constant I could find was that the DSTWO has a CPU in it to help out with emulation. Most of what I could find beyond that went from one extreme to the other, it was horrible or it was great.

After trying out the DSTWO for about a month this is what I’ve learned.

SNES: Works very well. Games with lots of sprites moving around at one time will slow down a little, Contra 3 for instance. I remember Contra 3 slowing down a bit way back when I was running it on a real SNES though. Games that use the SFX chip are super slow and not playable. I played a Link to the Past, Ogre Battle,  and Super Mario All Stars (+ World) just fine.

Genesis: About the same as the SNES emulation. The Sonics play well.

GBA: Never saw any problems.

NES, Gameboy, and Gameboy Color titles all play well.

Tip #1: If you try to load the DSTWO and you get a ‘No game inserted’, or ‘No game card inserted’ error, take the cart out and press it back in pretty hard. Its not a problem with how you formatted the card or any other some such. It’s a problem with the cart not seating down properly and the pins not making contact. Just give it a good push in.

Tip #2: The SD slot in the DSTWO is spring loaded. You push the SD card in and it clicks when it is seated. You push it in again and it clicks and the card pops out. The bits inside the card that handle the spring and the seating are cheaply made and wear out after a while. This happened after about ten in and outs for me. I’ve read on some forums about it happening sooner and of course some people never have a problem at all. My SD card will push in, but it no longer clicks and sticks. I ended up opening the DSTWO up, removing the spring and taping the SD card down. I suppose I could of (and should of) sent the card back for an exchange, but I didn’t want to be without it for that long.

 

 

 

After owning a Ouya for a week I’ve returned it to Amazon for a refund. The Ouya had problems that I couldn’t get over. I could have waited and hoped some future update would have fixed those problems, but after dealing with Ouya support and reading their forums I wasn’t confident it would happen.

The Bad

Overscan

I wrote a whole post about my frustrations with overscan. The fact that it had the problem was frustrating enough, the response I received about the problem put me over the edge. This problem and the response is the majority reason I returned my Ouya.

Support

The lack of support is appalling. There are issues, such as the overscan problem,  that make the Ouya unusable for people. The response you receive, if any, is that they’re working on it. In the case of the overscan problem, it’s been about three months and three firmware updates with no fix. I did get a response about my problem with overscan, but I felt the Ouya representative was annoyed I was even bringing it up. It’s a problem with your TV after all.

The touch pad

The touch pad on the controller is an awesome concept. Their implementation is bad and almost unusable. It’s hard to reach and when you do get a finger on it the cursor flies around on the screen almost at random. Also, you have to really give it a good thump for it to detect a click.

Games

I personally didn’t care much for the games. My selection was very limited though because of the overscan problem.

The Interface

The interface was overly simplistic and somehow sluggish. I didn’t like that my side loaded apps were in a different spot than my Ouya Store apps. The store having some options to sort would be nice.

Wifi

The Ouya’s wifi is just plain bad. Side by side with an ASROCK 330 using a no name USB wifi dongle the Ouya had worse reception,  higher ping, and a slower speed. I had to use a wired connection for XBMC to properly play videos on the Ouya.

The Good

I don’t want to come off as an Ouya hating fan boy. The Ouya has some great ideas and some great qualities.

XBMC and Plex ran like champs. They self corrected for my overscan problem. They both played all of my videos without any long buffering or stutters. (once on a wired network)

The emulators are awesome. I tried everything from the Atari 2600 to the PSX, all worked fantastically and corrected for the overscan.

Where it went wrong for me

I have an old XBOX running XBMC I use for emulators, then I have an ASROCK 330 for XBMC. My hope with the Ouya was to combine those into one machine. As an emulator and XBMC box Ouya did well. The overscan and the other problems (especially the overscan) just bugged the hell out of me. I didn’t want to use something I felt was broken.

I think the Ouya as a concept will ultimately be successful. Either the Ouya 2 will correct all of the problems, or a competitor will appear that does. If nothing else, the Kickstarter shows the market for a set top entertainment device that is open and hackable, I just don’t think the current Ouya is it.

I love David Nacho Cheese flavored sunflower seeds. I used to buy them by the case in 5.25 ounce packs from Amazon. Sometime last year Amazon stopped selling them, thinking this was just Amazon being weird I found other website to fuel the addiction. As time went on they too would stop selling the big packs, eventually leaving the small packs as my only option. Something was very wrong in the world.

After a lot of Googling I only found one other person that seemed concerned, complaining and asking questions in an Amazon review to no avail. What was going on with my beloved seeds? Why wasn’t the world in an outrage?

Not being able to find any information online, I sent an email to Conagra, the folks that own David. This was the response:

It’s great to hear you enjoy our DAVID Nacho Cheese Sunflower Seeds!  I’m sorry to say we have discontinued our 5.25 ounce and 1.75 ounce sizes, but we do still have our .8 ounce size available. – Christine

Nooooooo

Sears still sells the small packs of Nacho flavored seeds.  The small packs taste the same as the large packs. For me it takes about two packs to add up to what I’ll eat in a sitting.

 

 

I’m picky about wallets. I always have and still do only keep them in my right front pocket along with my car key fob. I rarely carry cash outside of an immediate need. When it comes to wallets the smaller and thinner the better.

Dopp Regatta Wallet

Dopp Regatta 88 Series Front Getaway Pocket

I’ve had my Dopp Wallet since I was a teenager. It sets the standard by which I judge all other wallets. Its thin, it has more than enough room for all of my cards, and it has an ID window. There is plenty of room for bills.  Your cards, bills, and ID are all easy to get to, but at the same time do not accidentally fall out. My only real problem with the Dopp Regatta is that I’ve used it for 15+ years and I would like something new.

I didn’t think I could get bored with a wallet, but over the last couple of years I’ve found myself buying other wallets and trying them out.

bookbook

Twelve South BookBook

The BookBook is a wallet and phone case combo. I used it for a couple of months with my iPhone 4S. In the end I went crawling back to my trusty Dopp wallet and glow in the dark Gameboy cell case because of the thickness and the mute problem explained below.

Pros

  • It looks good.
  • It makes holding your phone while browsing the web, playing games, or whatever, comfortable.
  • I received lots of compliments from people after they saw the BookBook.

Cons

  • Between my phone and my cards it is just too thick. Depending on my pants sometimes I couldn’t sit with it in my pocket.
  • The 4S version doesn’t have a hole for the camera, I had to slide my phone out of my wallet to take a picture.
  • Whenever I would hold the phone to my face to speak sometimes it wouldn’t detect this motion and turn the screen off. This led to me constantly putting the phone on mute with my cheek. This was beyond annoying.

Russian Mario WalletRandom Russian Mario Wallet

I purchased this wallet off of some guy on the Something Awful forums. The graphic on the front made it a must buy. The wallet is made out of vinyl, the same sort pool toys are made out of. When you put a card in it the vinyl grabs on and never lets go. I had so much trouble getting the cards out of the wallet it has never left my house. Vinyl is not a good material for wallets.

The Rubber Band Method

The ultimate slim wallet is the rubber band. Problem is you look like a homeless person when you try to pay someone. I tried a rubber band out for about a day, felt stupid, and stopped. I can’t give it any technical complaints. I didn’t like for the same reason I don’t turn all of my old jeans into shorts; standards.

 

The Ridge Wallet

The Ridge: Front Pocket Wallet

I’ll confess I have a soft spot for Kickstarters. The number of interesting or just plain unique products being developed through there piques my interest. Luckily I have yet to be burned by any failures. The Ridge is a Kickstarter I funded back towards the beginning of the year and received a few weeks ago. That’s a pretty fast turn around for a Kickstarter.

The wallet is two black brushed aluminum plates held together with heavy duty elastic. It has a nice heft to it. You can buy them with a money clip attached to the side. In a pinch you could cram some bills into the clipless version. This is the wallet I am currently using.

Pros

  • I really like the way it looks. Really do.
  • It’s small, the width/height is just slightly larger than a credit card.
  • You can be all cool and scan your cards without actually taking them out of the wallet.

Cons

  • Sometimes it gets all wobber jobby with my key fob in my pocket and becomes uncomfortable, leaving me to adjust things as if I’m playing pocket pool.
  • The two metal plates that make up the sides are about four credit cards thick. If these were thinner you would have a much thinner wallet.
  • While I have zero indication this will happen after my several weeks of use, I worry about the elastic wearing out someday.

Crabby Wallet

Crabby Wallet

This is another Kickstarter wallet. I have yet to receive it. Its a lot like The Ridge, except made out of cloth. I’m hoping the cloth will improve the pocket feel and thickness of The Ridge. I’ll update once I have a chance to try it out.

Updates!

 9/17/2013: I received my Crabby Wallet and I have posted a review of it here.

2/3/2014: I’ve reviewed the Kickstarter funded Simple Wallet.

 8/26/2014: I’ve found a wallet I really like.

I get asked, and am often in need myself, of sample DICOM files in various formats. By sample I mean no weird private tags and all of the identifying patient information has been removed. The files below are part of the collection I have built up over the years.

These files can be used to test applications you write using my PHP DICOM Class and can be opened in any image viewer, such as MicroDICOM.

Click on the thumbnail to get the DICOM file.

This is a setup I used for a number years before moving to a Sickbeard, Couch Potato, and sabNZBD. In this post I will show you how to use uTorrent to download videos and separate them out by type (TV Shows, Movies) via labels. XBMC will look in the folder uTorrent places the videos in for content to play.

Make Some Directories

You’re going to need some places to store your downloads. Makes these directories on your computer:

C:\Media
C:\Media\TV Shows
C:\Media\Movies

Setting up uTorrent

The goal with uTorrent is to apply labels to the torrents you are downloading so uTorrent will sort the files into directories for you.

The first thing you want to do is set up your labels. In uTorrent go to Options->Preferences->Advanced->UI Extras. Under Persistent Labels type in TV Shows|Movies. The screen shot below is an example.

utorrent_labels

Setting up uTorrent labels

Next you want to setup uTorrent to place your downloads in an easy to find directory, and to sort those downloads into directories with the same name as your labels. With the uTorrent preferences window still open from the last step, click on Directories. Then check mark ‘Move completed downloads to:’ and also check mark ‘Append the torrent’s label’. In the text box below type in C:\Media. The screen shot below is an example.

Setting the download location

Setting the download location

Now when you queue up a TV show or movie in uTorrent, you’ll want to apply a label to it. You do this by right clicking the downloading torrent and selecting the label from the menu.

Setting a label in uTorrent

Now you’re all set with uTorrent. Whatever you download and apply a label to will be sorted into directories for you.

Setting up XBMC

In XBMC we’re going to add

Go to Videos->Files->Add Videos.  Click on Browse and find C:\Media and then click on OK twice. You’ll get to a screen about setting content, just click on OK again.

Click on Add Videos again, then Browse and find C:\Media\Movies. Click OK twice. This time on the Set Content screen, change ‘This Directory Contains’ to Movies and pock mark ‘Movies are in separate folders that match the movie title’. When done click OK and let it refresh.

set_content_movies

Now we’re going to repeat for TV shows. Click on Add Videos again, then Browse and find C:\Media\TV Shows. Click OK twice. This time on the Set Content screen, change ‘This Directory Contains’ to TV Shows. When done click OK and let it refresh.

That’s it, a dead simple setup with uTorrent feeding XBMC. The easiest way to view all of your media is to go to Videos->Files->Media in XBMC and browse from there.

 

Torrents are not safe. Your IP address is visible to all. Eventually you will be caught and copyright infringement notices will be sent to your ISP. Using an Usenet Provider will not only protect you but allow you to download faster. I recommend NewsgroupDirect.