Monday, July 22, 2013
A5 - Area Estimation for Images with Defined Edges
Green's Theorem is a very useful way to compute areas ( or perimeters) of regions if one or the other is known. Supposing we have region R similar to the one shown in the Figure below
If we take C to be the collection of points in the boundary of R , choosing F1 = 0 and F2 = x gives us the equation below each relating a closed line integral to the area of R
Adding the two equations and averaging, we get
Which written in summation form and setting Nb to be t he number of pixels in the boundary of R then we have
I first created a circle of radius 0.7 using a code similar to the one I used in the Activity Scilab basics
stacksize(100000000);
nx = 500; //defines the number of elements along x and \y
ny = 500;
x = linspace(-1,1,nx);//defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);//creates two 2-D arrays of xand y coordinates
r = sqrt(X.^2 + Y.^2);//note element-per-elementsquaring of X and Y
A = zeros(nx,ny);
A(find(r<0.701)) = 1;
imshow(A);
with theoretical area pi*.7^2 = 1.53938
using the code
nx = 500; ny = 500; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of xand y coordinates
r= 0.401; // side of the square
S = zeros (nx,ny);
S (find (abs(X)<r & abs (Y)<r))=1;
imshow(S);
to form a square of side .4 with theoretical area .16
A4 - Image Types and Formats
This activity
entailed the familiarization of different image types and formats
A.) Image Types
1.) Binary
Images
Binary Images are
black and white images with pixel values 0 OR 1. This means that one pixel is
one bit. Fonts/text, fingerprints, particle tracks and signatures are some
images whose information can be adequately saved in binary form
Using the info =
imfinfo(filename) function of Scilab I got the properties :
Filename:
C:\Users\Vyke\Desktop\Activity 4\ablackandwhite.png
FileSize: 19827.
Width: 800.
Height:
771.
BitDepth 8
ColorType:truecolor
2.) Grayscale
Images
Grayscale images
Grayscale images
are images that are black AND white with each pixel (picture element) having a
value that ranges from 0 to 256 with 0 being pure black and 256 pure white. Different
values correspond to different intensities of “grayness” A value of 256
corresponds to the data stored in 8 bits or 1 Byte (28). Graytone
information similar to the ones found in x-rays and microscopic slides benefit
greatly from grayscale images.
Filename: C:\Users\Vyke\Desktop\Activity
4\audreygray.jpg
FileSize:
121635.
Width: 420.
Height:
563.
BitDepth: 8
ColorType :grayscale
3.) Truecolor
Images
Truecolor images
have pixels with three channels each of an intensity (that ranges from 0 to 256)
of red, blue or green light. These channels are composed together to create
other colors. Each pixel has 2563 possible colors. A lot of images
come in truecolor form with a 256x256 pixel image having a size of 256 x 256 x
3 because each pixel has 3 channels each with 1 BYTE of memory.
Filename: C:\Users\Vyke\Desktop\Activity
4\audreytruecolor.jpg
FileSize: 65180.
Width: 430.
Height: 500.
BitDepth 8 .
ColorType
:truecolor
4.) Indexed
Images
Indexed images
are used when images with lesser detailed is needed, but that compensate with
less memory (smaller data or color information) needed for the image. These
images have two sets of data, the image itself, and its index, which are
numbers that refer to colors in a color
map.
Filename: C:\Users\Vyke\Desktop\Activity
4\clownindex.png
FileSize: 64993.
Width: 560.
Height: 420.
BitDepth 8 .
ColorType
:truecolor
5.) High dynamic
range (HDR) images
Images of digital
x-rays, plasma, nuclear explosions require more that regular 8 bits. The images
are instead stored in 10 bits or 16 bits to achieve more detailed images.
Filename:
C:\Users\Vyke\Desktop\Activity 4\hdr.jpg
FileSize: 1472750.
Width:
1920.
Height: 1200.
BitDepth 8 .
ColorType
:truecolor
6.) Multi or
Hyperspectral
Satelite images are examples of images that make use of more the 3 channels that correspond to the primary colors and
instead have up to 100 channels (in the case of hyperspectral images).
Filename C:\Users\Vyke\Desktop\Activity
4\hyperspectral.jpg
FileSize:
93967.
Width: 432
Height: 341
BitDepth 8 .
ColorType
:truecolor
7.) 3D Image
3D images are
produced by either using: point clouds ( x,y,z) to store spatial data or even several 2D cross sections piled on top
of each other forming image stacks as in medical scans. These all generate the
spatial properties integral to 3d images.
Filename : C:\Users\Vyke\Desktop\Activity
4\3d.jpg
FileSize: 489617.
Width: 800
Height: 548
BitDepth 8 .
ColorType
:truecolor
8.) Temporal
images or Videos
B. Image Formats
Images can be saved under different
formats to suite your needs. Images can be significantly reduced in size to
cater to storage limits or can be saved to preserve quality.
Images in different file formats will
have different properties. There are two ways images can be saved: lossy and
lossless. Lossy compression techniques create very compressed files with some
loss in image data. These create images that aren’t as detailed as the original
ones but the changes are ignorable or irrelevant. Lossless compression
maintains the original image data with no loss of data for every pixel. These
are very important when even minute details of an image are important.
JPEG
JPEG stands for Joint Photographic
Experts Group and are used particularly for photographic pictures. This is the
standard format for images taken with digital cameras and for photographic
images in general. JPEG formats utilize the lossy compression meaning that some
of the original image information is not retained but are highly compact. This
makes it very easy to edit and makes JPEG files extremely flexible. JPEG
compresses files by retaining elements in an image that matter the most and
capitalizes on image contrast to decide what details to keep. This therefore
makes noisier images harder to compress that less noisier ones
TIFF
TIFF stands for Tagged Image File Format
and is widely used in printing and publishing. There make use of lossless
compression techniques keeping images more detailed but at the same time making
them bigger in size. Multiply layered images can easily stored in one TIFF.
They are excellent for images that need to be kept first and archived.
GIF
GIF stands for Graphics Interchange
Format and are images that can produce moving images by displaying images sequentially.
GIF images produce images that are not as detailed as original ones because 256
colors are maintained from an image with originally a lot more. GIF images load
segment-by-segment using interlacing. Images stored in GIF are optimal for
logos graphs and other images where color detail in unimportant but
transparency is. GIF supports transparency.
PNG
PNG stands for Portable Network Graphics
and are an excellent substitute to GIF images. PNG can compress images 5% to
25% more than in GIFs and support variable
transparency. This means users can decide on how transparent an image can be but
whose drawback are inconsistencies in displaying transparency depending on the browser.
PNG utilizes 2D interlacing making them load twice as fast as GIF images.
SVG
SVG or Scalable Vector graphics allows
very good quality graphics and animation that retain detail even when
increasing the size of the image. This can create images that looks the same whether
it’s the size of a small icon or scaled to fit a huge monitor. SVG can be
applied to still images and moving ones.
C.
Choosing the image I used as an example for a truecolor image, A truecolor picture of Audrey Hepburn, I will demonstrate the SIVP functions by turning it to a grayscale image and to a black and white image.
Using the code
im = imread('C:\Users\Vyke\Desktop\Activity 4\audreytruecolor.jpg');
gim= rgb2gray(im);
imshow(gim)
I successfully turned into a grayscale image
im = imread('C:\Users\Vyke\Desktop\Activity 4\audreytruecolor.jpg');
bim= im2bw(im,0.4);
imshow(bim)
I turned it into a black and white image
References:
[1] "Activity 3: Image Types and Formats 2010",
Dr. Maricor Soriano
[2]http://www.cambridgeincolour.com/tutorials/imagetypes.htm
[3] http://www.practicalecommerce.com/articles/1821-Image-Formats-What-s-the-Difference-Between-JPG-GIF-PNG-
Thursday, June 13, 2013
A3 - Scilab Basics
This activity capitalizes on Scilab's relative ease in operating with matrices.
nx = 100; ny = 100; //defines the number ofelements along x and y
x = linspace(-1,1,nx); //defines the range y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); //creates two 2-D arrays of xand y coordinates r= sqrt(X.^2 + Y.^2); //note element-per-elementsquaring of X and Y A = zeros (nx,ny); A (find(r<0.7) ) = 1; f = scf(); grayplot(x,y,A); f.color_map = graycolormap(32);
given by Ma'm Jing to create a circular aperture we were tasked to study it and use it to create
different images.
Fig 1. Centered circular aperture
The first image that was easiest to recreate was the annulus which is like two
concentric circles centered at the middle. I merely gave the region, with radii between 0.4 and 0.7, in the range [-1,1] in both axes, a value of 1 using the code shown below.
nx = 100; ny = 100; //defines the number ofelements along x and y x = linspace(-1,1,nx); //defines the range y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); //creates two 2-D arrays of xand y coordinates r= sqrt(X.^2 + Y.^2); //note element-per-elementsquaring of X and Y A = zeros (nx,ny); A (find(r<0.7 & r >0.4) ) = 1;// portion between circles of radii 0.4 and 0.7 is given a value of 1 f = scf(); grayplot(x,y,A); f.color_map = graycolormap(32);this results in the image shown below.Fig 2. Annulus with black centerAnother annulus can be created by switching the values of A making the default value 1 instead of an array of 0's using the below code,nx = 100 ; ny =1 00; //defines the number of elements along x and y x = linspace(-1,1,nx);//defines the range y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y);//creates two 2-D arrays of x and y coordinates r= sqrt(X.^2 + Y.^2)//note element-per-elementsquaring of X and Y A = ones (nx,ny);// made 1 A (find(r< 0.7 & r >0.4)) = 0;// portion between circles of radii 0.4 and 0.7 is gibven a value of 0 f = scf (); grayplot(x,y,A); f.color_map = graycolormap(32);This gives an aperture with a white center as shown below.
Fig 3. Annulus with white center
The next image that was easiest to create is the square centered at the middle. Using the code shown below where I defined the side of the square to be r with a length of 0.4 I was able to accurately derive such a square.
nx = 100; ny = 100; //defines the number of elements along x and y x = linspace(-1,1,nx); //defines the range y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); //creates two 2-D arrays of xand y coordinates r= 0.4; // side of the square A = zeros (nx,ny); A (find (abs(X)<r & abs (Y)<r))=1; f = scf(); grayplot(x,y,A); f.color_map = graycolormap(32);
Fig 4. White square aperture centered in the middle
The corrugated roof or the sinusoid along the x axis was the next image I created. I used the
da = gda() default function and x_label.text to label the x in order to show that the sinusoid is indeed oriented along the x-axis. I also made the x-axis range from -1 to 2.
nx = 100 ; ny =100; //defines the number of elements along x and y x = linspace(-1,2,nx);//defines the range. Note that x ranges from -1 to 2 and y ranges from -1 to 1 y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y);//creates two 2-D arrays of x and y coordinatesda=gda() da.x_label.text="x";// label for x axisA = sin(X.*%pi*7); f = scf (); grayplot(x,y,A); f.color_map = graycolormap(32);The image is shown here,Fig 5. Sinusoid along the x-axis forming a corrugated roof
The next image I created was the circular aperture with graded transparency (gaussian transparency). Using the definition of the Gaussian
nx = 100; ny = 100; //defines the number ofelements along x and y x = linspace(-1,1,nx); //defines the range y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); //creates two 2-D arrays of xand y coordinates r= sqrt(X.^2 + Y.^2); //note element-per-elementsquaring of X and Y A = zeros (nx,ny); A = (exp(-r) ) ;// using definition of Guassian f = scf(); grayplot(x,y,A); f.color_map = graycolormap(32);Fig 6. Gaussian transparent circular aperture
The last image I was able to create was the grating along the x-axis. I used the for loop to set allcolumns of A which are multiples of 10 to have a value of 1 yielding 10 gratings for the 100 elements in the x axis.nx = 100; ny = 100; //defines the number ofelements along x and y x = linspace(-1,2,nx); //defines the range y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); //creates two 2-D arrays of xand y coordinatesda=gda() da.x_label.text="x";// label for x axis ; // for x and y axes labels A = zeros (nx,ny); for r = 1:10:nx A(:,r)= 1 end f = scf(); grayplot(x,y,A); f.color_map = graycolormap(32);This gave me the image with 10 gray gratings across the x-axis. I used the x.label.textto properly identify the x from the y axis. I also made the range of x from -1 to 2 to differentiate it fromthe y axis. This is seen in the image belowFig 6. Gratings across the x-axis
Honestly, I think I deserve a perfect 10/10 because I did everything that was asked and I properly labelled all pictures ( they can stand alone) and adequately explained my rationale.
Subscribe to:
Posts (Atom)