Harsha projects

Yet another Tech blog !

Archive for April 2010

DICOM Image Viewer

leave a comment »

Hello All,

We have posted an artile “DICOM Image Viewer”  at Codeproject.com, Please visit:

http://www.codeproject.com/KB/graphics/dicomImageViewer.aspx

Thank for visiting.

Advertisements

Written by Harsha

April 29, 2010 at 11:29 AM

Window Level

leave a comment »

In any standard image processing application, we have something called Window Level.  On the net for Window Level, I didn’t get any convincing explanation. Except for one site.  Here I am trying to share my understanding of Window Level.  

What is Window and What is Level?
Level designates the center of the range of values mapped to grayscale. Window designates the extent of the range of either side of the level.
So range mapped is (level – window/2) to (level +Window/2).
For positive Window value, region less than (level-window/2) are clamped to black and regions greater than (level + Window/2) are clamped to white.
Here is an Image with filled with gray scale values ranging from 0 to 255.
Source: http://www.vtk.org/pipermail/vtkusers/2002-October/063541.html  

To begin with, I created an image, painted with stepped gray scale values from 0 to 255. As shown in the figure. The grayscale values are printed inside the rectangles. I deliberately put the black outline around the boxes labeled 240 and 255 since they merge with the background of the image. So our test image is ready.  

I used the popular image application, ImageJ for this experiment.  

When you open the image using ImageJ, and look at the Window Level Window, this is what you find.  

Test Image Opened in ImageJ

Here Level is ‘128’ that is midway between 0 and 255 of the 8 bit gray scale image; and Window is 255. So our range becomes  

Lower Value of the Range = (level – window/2)  

                = 128 – 255/2  

                = 0.5.  i.e., 1  

And Upper Value of the Range   = (level + Window/2) = 128 + 255/2 = 255.5 =~ 255.  

So all pixels values in the range 0 to 255 are visible.  

Window & Level

So, looking closer at  Window and Level: From the Image, Level is 128 and Range is 255. That is in a given 8 bit gray scale image, every gray scale will be visible.  

   

   

   

   

   

   

   

   

   

   

What happens if we set Level to 127 with Window to 2?  

Since the range is very small. We will see only pixel values between 126 to 128. Boxes which are painted with gray scan value less than 126 are all turned to BLACK and Boxes above 128 are all turned to WHITE.  

 
 
 

Level - 127 Window 2

When you set Level 0 and Window 1, you can see only one box which painted Black(Grey scan value 0). Take a look at these Images, as the with Window set to 1 and level start moving up from 0 to 100, All boxes will start showing up as BLACK in color since window set to 1.

At Level 142 and Window 1, it will display all boxes which are painted with less than 142 shows as BLACK and above 142 are all set to WHITE.

One can consider ‘Window’ as  Diameter of the circle and ‘Level’ as the center of the circle. More the diameter more the range, i.e, more boxes are visible or pixel with more gray scale values will be visible.

 

At Different Level and Window

Hope the article helped you understand the window and level. Thanks for reading the article. Feel free to comment.

Written by Harsha

April 29, 2010 at 11:23 AM

Display – Rectangular raw images.

leave a comment »

We have updated the article at Codeproject.com.  Updated article explain how to view the rectangular raw Images.

Please visit:
Rectangular raw Image

Thank you.

Written by Harsha

April 27, 2010 at 7:06 PM

Posted in Article, WebLinks

Tagged with ,

PNP Catalog at a Glance

leave a comment »

Here is an article about resources available on Internet about Patterns and Practices. Article lists all links to various downloads and homepages of of the PnP. Check out the WPF under “Reference Implementations”.

http://blogs.msdn.com/jmeier/archive/2010/04/20/patterns-practices-catalog-at-a-glance.aspx

Please comment and share your links and useful tutorials.

Thank you.

 

Written by Harsha

April 26, 2010 at 10:30 AM

Raw Image + WPF

leave a comment »

Hello All, We have published an article about opening a row Image in WPF at codeproject.com.
Please visit the link:

http://www.codeproject.com/KB/graphics/RawImageDisplayWpf.aspx

Written by Harsha

April 18, 2010 at 11:32 PM

Character occurrence

leave a comment »

How do you count all the occurances in a string?

Lets a string is “aabbccdda”, answer should be a ->3, b->2, c->2, d->2. There may be many ways to count the same.
One method would be Switch-Case statements.Don’t laugh it is still a good method. Another is compare the character with other and when it found increase the count. But here you check too many times. One will atleast iterate n*(n+1)/2 times, Where n is the number of characters in a string.

Here is a code snippet for counting occurances of all the Character in a string. Thanks to vidya.

static public Dictionary<char,int> Parse(string sequence)
{
    Dictionary<char,int> SequenceCount = new Dictionary<char,int>();
    for (int i = 0; i < sequence.Length; i++)
    {
        int Count = 0;
        bool isAvailable = SequenceCount.TryGetValue(sequence[i], out Count);
        
        //On Available You remove that character and Add Again with Count +1.
        if (isAvailable)
            SequenceCount.Remove(sequence[i]);
        //On Not Available, you have to add the character to Dictionary and increase
        //the count. Remember 'Count' still 0.
        SequenceCount.Add(sequence[i], Count + 1);
        
    }

    return SequenceCount;

}

Here is how you call the same in Main():

static public void Main()
{
    string s = "aabbccddeeffabcdefa23";
    Dictionary<char,int> SequnceCount=Parse(s);
    foreach (KeyValuePair<char, int> key in SequnceCount)
    {
        Console.WriteLine("{0}  {1}", key.Key,key.Value);
    }
    Console.Read();
}

Please free to comment on the same. Let me know, if you found any such problems and answers.
Thanks for your time.

Written by Harsha

April 18, 2010 at 11:27 PM

Posted in C Sharp

Tagged with