Skip to main content

Activity 3: Image Types and Formats

In this activity, we will explore different image types and file formats.
There are four basic image types: binary, grayscale, truecolor, and indexed images. Here are some examples of each type together with their information.
Note: imfinfo outputs the following image information-> File Name, File size (bytes), Width, Height, bit depth, and Color type

1. Binary image

The extracted image information using Scilab imfinfo are:







(The bit depth is 8 because imfinfo in SVIP module only outputs either grayscale or true color and represents the 1’s and 0’s of a binary image with 255 and 0 as shown below.)


2. Grayscale image
Image information:
3. Truecolor images
Image information:
*note the addition of another channel in the image array which gives the RGB values of each pixel in the image.
4. Indexed images

Image information:
The color map of the image was obtained from Gimp v2.8:
Some of the more advanced image types are as follows:
1. High dynamic range (HDR) images


2. Multi-/Hyper-spectral images
3.
Now, it's time to do some image processing. First, we try to convert a truecolor image to grayscale and binary images using the rgbtogray and im2bw commands. In this example we will use the following 1280pixels x 800pixels true color image with array size of 800x1280x3:
(mostly%20anime)/anime_wallpapers_mOole.ru_122.jpg/

Converted to grayscale, the image now only has a single layer making its array size just 800x1280.

When converted to binary form using a threshold value of 0.5, that is, a pixel which has a value greater than 255*0.5 will be assigned a value of 1 and 0, otherwise.   Note that its array size is similar to that of a grayscale image.

The code used to do these is as follows:
stacksize(100000000);//set stacksize
I = imread('C:\Users\Tin\Desktop\AP_186\Act3\anime.jpg');
conv = rgb2gray(I);//convert to grayscale
imwrite(conv, "grayscaled.png")//save grayscaled image
BW = im2bw(conv,0.6)//convert to bw image
imwrite(BW,"thr_0.6.png");//save bw image


Next, we open the scanned image that we used for Activity 1 and converted it to a grayscale image. The original and the grayscaled images are shown below (left:original ; right: grayscaled):

Taking the histogram of the image, I got:
From the histogram, I selected the threshold to be at 150, which is approximately the point where the distribution starts to flatten. The pixels with values greater than 150 may already be contributions from the lighter background, especially those which result from scanning the page. The threshold value used for the imhist command is then 150/255 ~ 0.6 The resulting binary image is shown below.

The implemented threshold has effectively separated the lines in the graph from the background. I tried to use other threshold values that are higher and lower than 0.6. When the threshold is decreased, the lines become fainter, and when it is increased they become darker and the dark areas due to the scan become visible. The results are shown below (left: threshold = 0.5; right: threshold = 0.7):


















The code used for this part is as follows:
stacksize(100000000);//set stacksize
I = imread('C:\Users\Tin\Desktop\AP_186\Act3\scan0033_2.jpg');
conv = rgb2gray(I);//convert to grayscale
imwrite(conv, "grayscaled.png")//save grayscaled image
[counts, cells]=imhist(conv);//take histogram of grayscaled image
histplot(cells, counts);//plot histogram
BW = im2bw(conv,0.6)//convert to bw image
imwrite(BW,"thr_0.6.png");//save bw image

In this activity, I saved all the images that I produced in PNG format. There are other formats in which images may be saved depending on the required image size and quality. The following are some of them:
  • JPEG format - The Joint Photographic Experts Group has developed the JPEG file format. It is good for use in photographic images. Most images captured by cameras, are saved in JPEG format because of its compact size which makes it easier for processing. However, this portability comes at the expense of lossy image compression which reduces the quality of the saved image.
  • BMP or Bitmap image file, also known as device-independent bitmap, is the standard format for Windows operating system which stores bitmap images. It supports 2D images with various dimensions, resolutions, color type, and color depth. It is impractical to use on the web because of the large file size of images in this format.
  • GIF or Graphic Interchange format is an image file format developed by Compuserve which allows animations but is limited when it comes to color representations. It can only support up to 256 colors, unlike its counterparts. Hence, it is not ideal for use in application such as photography and archiving.  
  • PNG, which stands for Portable Network Graphic, is a lossless image compression format which was developed mainly to overcome the limitations of the GIF format. It employs a compression technique called deflation. It allows storage of more image attributes and larger greater bit depths. In particular, PNG files may store gamma values, background color, and textual information. The standard allows up to 16 bits for each color channel. PNG files may be used in many different application and is supported by the web.
  • TIFF or Tagged Image File Format is another lossless image compression format developed by Aldus (now Adobe Systems) which delivers high quality images but at the cost of larger file sizes. Basic TIFF images include bilevel, grayscale, palette/indexed, and true color (RGB). RGB TIFF images are capable of holding up to 16.7M colors while indexed and grayscale images only have 256 colors or shades. TIFF images are mostly used for archiving important images. Due to its large file size, there is little support for TIFF images on the web.
I give myself a 10 for this activity because I was able to do all the things that should be done. Also, I have had a better understanding of image types and formats from this activity.
References:
1. http://www.coolutils.com/bmp
2. http://www.coolutils.com/gif
3. http://www.coolutils.com/jpeg
4. http://www.fileformat.info/format/png/corion.htm
5. http://kb.iu.edu/data/afjn.html

Comments

Popular posts from this blog

Activity 10 Applications of Morphological Operation 3 of 3: Looping through images

When doing image-based measurements, we often want to separate the region of interest (ROI) from the background. One way to do this is by representing the ROIs as blobs. Binarizing the image using the optimum threshold obtained from the image histogram simplifies the task of segmenting the ROI. Usually, we want to examine or process several ROIs in one image. We solve this by looping through the subimages and processing each. The binarized images may be cleaned using morphological operations.  In this activity, we want to be able to distinguish simulated "normal cells" from simulated "cancer cells" by comparing their areas. We do this by taking the best estimate of the area of a "normal cell" and making it our reference.  Figure 1 shows a scanned image of scattered punched papers which we imagine to be cells examined under the microscope. These will be the "normal cells." Figure 1. Scattered punched paper digitized using flatbe...

Activity 12: Basic Video Processing

Hello!  In this activity we will try to process a video of a kinematic event in order to extract information such as constants, frequencies, etc. For our group, we took a video of a 3D spring pendulum which we observed in one plane. We would like to trace its path and then try to determine its phase-space plot. The mass was covered in masking tape with the bottom colored red to facilitate easier segmentation. The video was taken using a Canon D10 camera at frame rate of 30fps.  Media 1. Video of the spring pendulum (first 50 frames only) The frames of the video were then extracted using Avidemux 2.5. The mass was then segmented from each frame using parametric segmentation. The patch of the region of interest (ROI) used for color segmentation is shown in Figure 1. Figure 1. Patch used to segment ROI  Using morphological operations, particularly Open and Close operations, the segmented images were cleaned. The extracted frames for different observation...

Activity 7: Morphological Operations

When talking about morphology, what immediately comes to mind are the forms and structures or shapes of objects. Hence, performing morphological operations imply that the shape or form of an object is altered.       In this activity, we will perform morphological operations on binary images. In particular, we make use of erosion and dilation . Erosion and dilation were performed on the following: 1. A 5×5 square 2. A triangle, base = 4 boxes, height = 3 boxes 3. A hollow 10×10 square, 2 boxes thick 4. A plus sign, one box thick, 5 boxes along each line Using each of the structuring elements below: 1. 2×2 ones 2. 2×1 ones 3. 1×2 ones 4. cross, 3 pixels long, one pixel thick. 5. A diagonal line, two boxes long, i.e. [[0 1],[1 0] ].      When performing these operations, it is important to note the “anchor” or “origin” of the structuring element in order to give an accurate prediction of the result. For the 2x2 ones, 2...