Thursday, June 18, 2020

How to Create a Course in Moodle? Step-by-Step Guide

How to Create a Course in Moodle? Step-by-Step Guide


What is moodle?

Moodle is a web based software deployed by Martin Dougiamas. Moodle is for training & education providers as a method to Manage the delivery of a educational content to its users.

It will deliver typically video and files to users and keep track of their progress through such content ( training / education) including quizzes too.

Moodle provide personalized learning environments to teachers, administrators and learners.

What MOODLE stand for?

Moodle stand for 'Modular Object-Oriented Dynamic Learning Environment' 

Moodle is a free e-learning platform for conducting online classroom. It is open-source software LMS (Learning Management System).

Installing Moodle

  • Setup your own server -You can download the software onto your own web server or local server.
  • Setup on Gnomio online tool - Here you can activate your free virtual classroom within minutes.

What is Gnomio


Gnomio is a online open source learning tool.

Here you can create your free subdomain and secure access to complete administration privileges.

Steps to setup moodle with Gnomio -

  • Visit site https://www.gnomio.com
  • Create your own Moodle site

create-moodle-site-with-gnomio

  • After successfully email verification & creating the site, login using admin id and password.

Steps to create course category in moodle


  • Select Site Administration
  • Course
  • Add a Category
  • Create New Category

How to Create a Course in Moodle? Step-by-Step Guide

As example, add two categories as Engg-CSE and Engg-IT


Steps to create course in moodle


To add a course under a category

  • choose Category i.e Engg-CSE
  • Click on Create Course
  • Add New Course Page gets displayed.
  • Enter Course Name Short name
  • choose a Course Category to add a course under it.

Create-course-in-moodle-1

Create course under category

Create-course-in-moodle-2As example, we are creating course Java under Engg-CSE category, so choose course category as Engg-CSE.

 

Wednesday, April 22, 2020

Web Application Architecture


Web Application Architecture forms the transition from analysis to implementation:





Break the functional requirements and quality requirements down into software components and their relationships , interfaces in an iterative approach.





conceptual view - identifies entities of the application domain and their relationships;





runtime view- describes the components at system runtime, e.g., servers, or communication connections;





process view - maps processes at system runtime with synchronization and concurrency;





implementation view - system’s software objects, e.g., subsystems, components, or source code.





Patterns Significance





Patterns can only represent a guideline for the problem. architect has to adapt patterns to the respective problem and constraints





A pattern language describes the interconnections of related patterns on different abstraction levels, different uses for patterns.





Architecture patterns- patterns map fundamental structuring mechanisms for software





systems. Describes architectural subsystems, relationships and interplay.





Ex. - Model-View-Controller (MVC)





Design patterns –





Design patterns abstract from a specific programming language, It solve a design problem within a defined context





Ex - Publisher-Subscriber pattern





Categorizing Architectures





Layering aspect:





Layering means that software systems are structured in several tiers to implement.





2-Layer Architectures , N-Layer Architectures





Ex- J2EE





Data aspect:





Data can be structured or non-structured.





Structured data follow a defined scheme like tables in a relational database or XML structures in a document.





Non-structured data are multimedia contents,





Ex. images, audio, and video.





Components of a Generic Web Application Architecture





Components of a Generic Web Application Architecture




Client: - Generally a browser (user agent) is controlled by a user to operate the Web application.





Firewall: A piece of software regulating the communication between insecure networks





Proxy: A proxy is typically used to temporarily store Web pages in a cache. e.g., adapting the contents for users (customization), or user tracking.





Web server: A Web server is a piece of software that supports various Web protocols like HTTP, and HTTPS, etc., to process client requests.





Database server: This server normally supplies an organization’s production data in structured form, e.g., in tables.





Components of a Generic Web Application Architecture





Content management server:





Similar to a database server, a content management server holds contents to serve an application.





These contents are normally available in the form of semi-structured data, e.g., XML documents.





Application server: An application server holds the functionality required by several applications, e.g., workflow or customization.





2-Layer Architectures





2-Layer Architectures




A client request can point directly to static HTML pages, without requiring any processing logic on the server layer,





Dynamic HTML pages include script instructions directly in the HTML code,





The application logic, or dynamic HTML pages, can use services like user identification or data encryption when the HTML response is generated.





N-Layer Architectures





N-Layer Architectures<br/><br/>




They typically consist of three layers,





data layer, providing access to the application data





business layer, hosting the business logic of the application in an application server





presentation layer, which renders the result of the request in the desired output format.





Architectures for Web Document Management





Content management architectures support. the integration of documents from different sources, a mechanism to integrate these contents into Web applications





A Web server receives a client request and forwards it to a content delivery server.





Architectures for Web Document Management





The content can be available directly on that server (in static form as a document, or in a content database), or it can be accessible externally.





Depending on the type of integration, external content can be retrieved either by accessing external databases





Ex- Cocoon 2 framework for publication of XML documents in the Web





Architectures for Multimedia Data





Architectures for Multimedia Data<br/>




Basically, multimedia data, i.e., audio and video, can be transmitted over standard Internet protocols like HTTP or FTP





Protocols for multimedia data communication





Real Time Protocol (RTP), Real Time Streaming Protocol (RTSP) Ex – Youtube , amazon prime , netflix





Hypertext Modeling





hypertext modeling is also known as navigation modeling.





It is to specify the navigation through the content of a Web application





These navigation paths available to the users.





Download pdf





Video Lecture






https://youtu.be/ojT45wt6PRs
Web Application Architecture





Monday, April 13, 2020

Categories of Web Applications


What is Web Application





A Web application is a software system based on technologies and standards of the World Wide Web Consortium (W3C) that provides Web specific resources such as content and services through a user interface, the Web browser





What is Web Engineering





Web Engineering is the application of systematic and finite approaches (concepts, methods, techniques, tools) to cost-effective requirements analysis, design, implementation, testing, operation, and maintenance of high-quality Web applications





Topics covered





  • What is Web Engineering
  • What is Web Application
  • Categories of Web Applications
  • Characteristics of Web Applications






















Categories of Web Applications





Document centric Web sites





Document centric Web sites Web pages are stored on a Web server as ready-made, i.e. static, HTML documents and sent to the Web client in response to a request.





These Web pages are usually updated manually using respective tools Examples •news sites •Organization sites, informative sites










Transnational Web applications





provide more interactivity, giving the user the possibility of not only interacting with the application in a read-only manner, but also by performing updates on the underlying content.





Examples - Online banking, online shopping, and booking systems belong in this category.










Workflow-based Web applications





Workflow-based Web applications allow the handling of workflows within or between different companies, public authorities, and private users





Examples - Business-to-Business solutions (B2B solutions) in e-commerce, e-government applications in the area of public administration, or Web-based support of patient workflows in the health sectors










Collaborative Web applications





Collaborative Web applications support shared information and workspaces in order to generate, edit, and manage shared information.





They are also used to keep logs of many small entries and edits (as in Weblogs), simple chat rooms, as scheduling systems, or as e-learning platforms like google class room.










Portal-oriented Web applications





Portal-oriented Web applications Portal applications provide data in an easily understandable format, modify or manipulate the data, and communicate with companies or individuals about the data.





Contents in a web portal are dynamic and changed frequently. The visibility of one content changes from person to person which means a content could be unique.





portal acts as a gateway to world wide web and provides many services.





Horizontal portals are public website which tries to deliver every type of service that its users may need.





Vertical portals work in a user-centric manner and deliver information that is organization-specific.










ubiquitous Web applications





ubiquitous Web applications provides customized services anytime anywhere and for any device, thus facilitating ubiquitous access.





It is either personalization or location-aware services or multi-platform. It can provide analysis of data collected from sensors.





Most of the Internet of Things (IOT) devices are based on Ubiquitous Computing.





examples are: Apple Watch, Amazon Echo Speaker •Fitbit,  Electronic Toll Systems,  Smart Traffic Lights •Self Driving Cars





ubiquitous computing is new business models and services. TIMES industry (Telecommunications, Information technology, Multimedia, Education and Entertainment, Security)





Reference Book - Web Engineering by Gerti Kappel, Birgit Pr¨oll, Siegfried Reich, Werner Retschitzegger


Wednesday, December 4, 2019

7 Key terms of Cloud Computing


What is Cloud Computing?




What is cloud computing?Cloud computing is the ability to access and manipulate files from a remote site. You need an internet connection to access the files. all Google services, Facebook, Twitter, and Instagram are all examples of cloud-based applications.




It is the delivery of different services through the Internet, including data storage, servers, databases, networking, and software. 




With a web browser, clients can access their information and engage different applications without investing in expensive software or paying huge license fees to use some web infrastructure.




cloud computing
Credit: wikimedia



It is multiple computers with unlimited storage with high processing speed located in specific areas around the globe. These computers are referred as data centers.




Cloud services are provided as Private and public. Private is only accessible within an organisation while public is accessible to the general public. Security is more enhanced in private than in public.




Three services model are based on cloud computing-




cloud services IaaS PaaS SaaS
Credit: wikimedia



Infrastructure as a service (IAAS) -




It refers to cloud-based services, such as pay-as-you-go storage, networking, and virtualization. This is access to resources offered by the provider . It can be virtual devices or physical devices. The most common examples are Amazon Web Services, Microsoft Azure, etc.




IaaS helps enterprises create and manage their data as they scale, paying for the server space that they used to develop hardware or software.




Software as a service (SAAS) - 




It is cloud-based software available for purchase on a subscription basis. It is mostly used for apps that need both web and mobile access.




SaaS products don't need to be downloaded and installed on individual devices. Most of them can be run directly from web browsers. It should be taken into account that customers are not responsible for hardware and software updates.




The most common examples are DropboxJIRA, Salesforce




Platform as a service (PAAS) -




It refers to cloud-based platform services that provide developers with frameworks that they can use to create custom apps.




The model provides programmers with a platform that is used to create software delivered via the Internet. All servers, storage, and networking can be controlled by the business or a third-party provider. The most known examples are Windows AzureGoogle App Engine, Openshift




PaaS makes development, testing, and deployment processes fast, easy, and cost-effective.








Cloud Deployment Models




A cloud deployment model represents a specific type of cloud environment. It is distinguished by ownership, size and access.




There are important deployment models like public cloud, private.cloud, hybrid cloud and community cloud. Other deployment models include multi-cloud, distributed cloud, inter cloud, Big data cloud, High Performance Computing (HPC) cloud etc.




Public Cloud




A public cloud is a publicly accessible cloud environment owned by a third-party cloud provider. Examples of public cloud are Amazon Web Services (AWS). Google Compute Engine, Microsoft Azure etc.




The cloud provider is responsible for the creation and on-going maintenance of the public cloud and its IT resources.




The advantages of this model are easy to set up at low cost as provider covers the hardware, application and bandwidth cost. This model is scalable to meet growing needs.




No resources are wasted from the user's perspective as the payment is done on a pay-per-use basis.




cloud services IAAS PAAS SAAS



Private Cloud




A private cloud is owned by a single organization. Private clouds enable an organization to use cloud computing technology as centralized access to IT resources by different is location, or department of the organization.




When a private cloud exists as a controlled environment, the risks and challenges are less compared to public cloud. but regular maintenance is required for deployment private model.




Hybrid Cloud




Hybrid cloud is a cloud environment comprised of two or more different cloud deployment models. These different deployment models are pooled together by standardized tools.




For example, a cloud consumer can choose to deploy private cloud services to process sensitive data and other less sensitive cloud services to a public cloud. The result of this combination is a hybrid deployment model.




Hybrid deployment architectures can be complex challenging engine to create and maintain due to the potential disparity in cloud environments.








HPC Cloud




HPC cloud refers to the use of cloud computing services and infrastructure to execute High
Performance Computing (HPC) applications.




These applications consume more computing power and memory and are traditionally executed on clusters of computers.




Various vendors offer servers that can support the execution of these applications.




In HPC cloud (High Performance Cloud), the deployment model allows all HPC resources to be inside the cloud provider infrastructure.




The adoption of cloud to run HPC applications started mostly for applications composed of independent tasks with no inter-process communication.




Following topics are nicely explained in Video Tutorial:




  • 1. Why cloud computing?
  • 2. What is cloud computing?
  • 3. Types of cloud computing?
  • 4. Cloud providers
  • 5. The lifecycle of a cloud computing solution
  • 6. Cloud computing with AWS
  • 7. Demo - AWS EC2 and AWS S3




https://youtu.be/RWgW-CgdIk0








Thursday, August 1, 2019

#1 JavaScript Basics let variable & arrow functions


This JavaScript tutorial explains advantages, Adding JavaScript into an HTML Document, How to declare variables in JavaScript, How to define a regular and arrow function in JavaScript. here you can code download the difference let and var variable declarations, regular and arrow function definitions with examples.





Advantages of JavaScript





  • JavaScript is client side programming language used to create responsive, interactive elements for web pages and enhancing the user experience.
  • It is an object oriented scripting language. It is used in web pages along with markup language HTML.
  • This is a high-level, interpreted programming language.
  • JavaScript can be executed without compiling. This is done by JIT (Just In Time) compilation. This dynamic compilation is done inside the execution engine.
  • Setup for JavaScript is very easy, as it works inside browser. It is used in web pages and loaded in the browser.
  • JavaScript used to program the behavior of web pages. It used in many desktop and server programs also.
  • This is a scripting language used to create and control dynamic website content like animated graphics, scrolling video, and interactive maps.
  • JavaScript is event based language. We can execute different code segments whenever a certain event occurs. It means that, if a user clicks a button or moves a mouse over the object then specific code segment is get executed.




Adding JavaScript into an HTML Document





We can add JavaScript code in html by 3 ways,





  1. Between the body tag of html
  2. Between the head tag of html
  3. In .js file (external JavaScript)




Between the body tag of HTML





Between the body tag of HTML
javascript between body tag




we can directly write JavaScript commands inside script tags in HTML code.





type is attribute of script tag whose value is text/javascript. it specifies the code inside script is JavaScript code.





Write above code in notepad editor, save file as test1.html and open file in any browser application from your machine.





here write method of document object, Writes specified text directly to the HTML document. we can format this text by html tags.





alert method displays the text in message box inside the browser.





Between the head tag of HTML





Between the head tag of HTML
javascript between head tag




In .js file (external JavaScript)





create a myscript.js file in notepad editor or any text editor, type following code and save file.





external JavaScript file
external-js-file




create file testjs.html and type following code.





javascript external-file
javascript-external-file




Here the reference of myscript.js file is given in body tag of html code. so the contents of external js file is get linked with html code. This way we can link one js file to multiple html code i.e multiple web pages. so that code re-usability and updation is easier.





This js file can hold multiple functions with or without parameter for specific tasks. so once we linked JavaScript file with web page, we can call any function for multiple times.





How to declare a let variable in JavaScript?





A JavaScript variable is a name of storage location. JavaScript is a dynamic type language, means we don't need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var keyword to specify the data type. It can hold any type of values such as numbers, strings etc.





There are two types of variables in JavaScript : local variable and global variable. JavaScript variables are case sensitive. variable name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.





There are two types of variables in JavaScript : local variable and global variable. JavaScript variables are case sensitive. variable name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.





let is a keyword used to declare variables in JavaScript. There are two ways you can declare variables in JavaScript let and var. let keyword is introduced ES6. ES6 refers to version 6 of the ECMA Script programming language. ECMA Script is the standardized name for JavaScript.





The difference is scoping. var is scoped to the nearest function block and let is scoped to the nearest enclosing block, which can be smaller than a function block. Both are global if outside any block.





Also, variables declared with let are not accessible before they are declared in their enclosing block. this will throw a Reference Error exception.





difference let & var variable
let-var-difference-example




here, let a1=100 ,b=20 is variable declaration. document.write(a+b) will print sum=120.





document.write(z) prints value of z as undefined. because z is declared after access of variable using var keyword.





document.write(k) gives reference error, because k is declared after access of variable using let keyword. scope of let variable is smaller than var variable.









JavaScript local variable





A JavaScript local variable is declared inside block or function. It is accessible within the function or block only.





JavaScript global variable





A JavaScript global variable is accessible from any function. A variable i.e. declared outside the function. In a web page, global variables belong to the window object. All the scripts in page can access and modify global variable.





How to define a function in JavaScript





A function is a subprogram designed to perform a particular task. parameter values can be passed into functions and used within the function. In JavaScript, Functions always return a value. lets see following example.





Regular Function in JavaScript





function name(parameters){
statements
}





How to define a arrow function in JavaScript
JavaScript Function




calCube is user defined function in JavaScript. It is defined in head section of web page. This function accept single parameter n. it returns the cube of number as output. This function is called from script tag of body section and result is displayed in paragraph tag. result is the id of paragraph tag.





Arrow Function in JavaScript





Arrow functions allow us to write shorter function syntax. It is a new feature introduced in ES6.





let f = (parameters) => { // body of the function };





How to define a arrow function in JavaScript
regular-and-arrow-function




Here , calCube is regular function and AcalCube is arrow function.





var AcalCube = (n) => {return n*n*n;}

here AcalCube is function name and n is single parameter of function.





Thursday, July 11, 2019

How to connect xampp mysql database with JDBC Netbeans project


This tutorial explains steps for mysql connector java i.e connect mysql database to netbeans java project. This consists of 4 steps as,





  • Install XAMPP for MySQL
  • Create User, Database and Table in MySQL
  • Generate connection string in Netbeans project
  • Steps to insert records in table using JDBC.




Install XAMPP for MySQL





XAMPP is an open source software developed by Apache friends. XAMPP software package contains Apache distributions for Apache server, MariaDB, PHP, and Perl. And it is basically a local host or a local server.





Installation of XAMPP software is very easy. You can download XAMPP from here and just complete the installation wizard. then open XAMPP control panel and start apache and mysql services as shown in image below.





XAMPP Control panel




Create User, Database and Table in MySQL





To create a new database in MySQL, open browser, type localhost, then click on phpMyAdmin link, click on users tab and create new user and database.as shown in image below.









Click on Add new user and enter username , password & host-name localhost. the important step is select checkbox Create database with same name and grant all privileges & global privileges.then click on go button.





To Create Table.





Click on Database Tab, click on database name which just created. then enter table name and click on go button.





create table in mysql




Generate connection string in Netbeans project





Open Netbeans, create new project, right click on project, select add library. select Library for MySQL JDBC Driver. then click on Add Library. Here you can download netbeans if you don't have.





steps to add library in netbeans java project for mysql connection string




Create New Database Connection





Then Goto Services tab, right click on database , click on new connection , select driver MySQL (Connector /J Driver), next , enter username and password of mysql database which you created. and check connection by test connection button. then copy JDBC URL which is connection string.





Create New Database Connection in netbeans mysql database




Steps to insert records in table using JDBC





There are 6 steps to apply DML( Data Manipulation Language) statements on database using JDBC.





Load Driver - This instruction for JVM to load the desired driver implementation into memory for further JDBC requests. You can skip this step for JDBC 4.0 API because this load driver instruction in integrated in getConnection Method.





//step-1 
Class.forName("com.mysql.jdbc.Driver");




Create Connection Object - The DriverManager class acts as an interface between user and drivers. Its static method is getConnection. This method take 3 parameters as connection-string(JDBC URL), database username & password.





//step-2                             //connection string, username, password
Connection con=DriverManager.getConnection(connectString,"javadbuser","1234");




Create Statement Object - Statement object is created by methods of connection object. createStatement, preparedStatement & callableStatement.





Write SQL statement - Here you can write SQL DML statements like INSERT, SELECT, UPDATE & DELETE. Here we insert a record in table using INSERT query.





//step-3        //Table fields: bookid,booknm,bookauthor,price
String q="insert into book values(111,'Java','Mr.X',700)";




Execute Query on database - after writing a query string, we have to execute it on database. Query can be executed on database table by executeUpdate method of statement class.





//Step-4 //execute query on database
st.executeUpdate(q);




Close connection - Active connection is terminated by close method of connection class.





//Step-5 //Close Connection.
con.close();




Here is complete java code to insert a record into database using JDBC steps.





package testmysqldb2;
import java.sql.*;
import javax.swing.JOptionPane;
/**
* @author Arvind Pande
*/
public class TestMysqlDB2 {
public static void main(String[] args) {
try
{
String connectString="jdbc:mysql://localhost:3306/javadbuser?zeroDateTimeBehavior=convertToNull";

//Step-1 //load driver
Class.forName("com.mysql.jdbc.Driver");

//Step-2 //Create Connection Object
//connection string, username, password
Connection con=DriverManager.getConnection(connectString,"javadbuser","1234");

//Step-3 //Create Statement object
Statement st=con.createStatement();


System.out.println("Ok,Connection is done");

//Step-4 //Database Query to insert Record
//Table fields: bookid,booknm,bookauthor,price
String q="insert into book values(111,'Java','Mr.X',700)";

//Step-5 //execute query on database
st.executeUpdate(q);

System.out.println("Data inserted successfully..");

//Step-6 //Close Connection.
con.close();


}
catch(Exception ex)
{
System.out.println("Error: "+ ex.getMessage());
}
}
}




Goto Phpmyadmin and click on table to verify data insertion.










Wednesday, April 17, 2019

HAAR Wavelet Transform - Image Compression Matlab Program


What is HAAR wavelet transform?





Wavelet transform divides the image information into approximation and detail sub signals.





approximation sub signal shows the general trend of pixel values and other detail sub signals shows the vertical, horizontal and diagonal details in the images.





If these details are below threshold then they can be set to zero. The greater the number of zeros the greater the compression ratio.





If the amount of information retained by an image after compression and decompression is 100% then the compression is lossless. It means image can be reconstructed exactly.





This occurs when the threshold value is set to zero, meaning that the details have not been changed. If any value is changed then energy will be lost and thus loss compression occurs.





If more zeros are obtained, more energy is lost. Therefore, a balance between the two needs to be found out.










Haar wavelet compression





Haar wavelet compression is an efficient way to perform both lossless and loss image compression. It relies on averaging and differentiating values in an image matrix to produce a matrix which is sparse or nearly sparse.





A sparse matrix is a matrix in which a large portion of its entries are 0. A sparse matrix can be stored in an efficient manner, leading to smaller file sizes.





Haar wavelet basis can be used to represent this image by computing a wavelet transform.





first the average the pixels together, pairwise. It is calculated to get the new lower resolution image with pixel values.





Clearly, some information is lost in this averaging process. We need to store some detail coefficients to recover the original four pixel values from the two averaged values.





Haar Transformation for Image Compression




Let A be one of our 8×8 blocks and HTAH be the Haar wavelet compressed image of A. HTAH contains many detail coefficient which are close to 0.





We will pick a pixel value > 0 and set all of the entries of HTAH with absolute value at most to 0. This matrix now has more 0 values and represents a more compressed image.





H1,H2 and H3 have orthogonal columns.. If we set  H = H1.  H2.  H3, then H is orthogonal. This means that H−1 =  HT. Thus, to decompress an image, we only need to transpose H rather than calculate its image.





Moreover, because an orthogonal matrix preserves angles and lengths, using H usually results in better image quality when applying lossy compression.





Matlab Program - Image Compression using HAAR Transformation algorithm.





clc;close all;clear all;
warning off;
bs=4; % block size

im_name='cameraman1.jpg' % change image name
delta=0.01;
in=double(imread(im_name));
rgb=double(imread(im_name));
len=length(size(rgb));

for j1 = 1:3
t=rgb(:,:,j1);

n=bs;

Level=log2(n);
if 2^Level<n, error('block size should be 2,4,8,16');end
H=[1];
NC=1/sqrt(2);
LP=[1 1];
HP=[1 -1];
for i=1:Level
H=NC*[kron(H,LP);kron(eye(size(H)),HP)];
end
H1=H;
H2=H;
H3=H;
H1=normc(H1);
H2=normc(H2);
H3=normc(H3);

H=H1*H2*H3;
x=t;

y=zeros(size(x));

[r,c]=size(x);
for i=0:bs:r-bs
for j=0:bs:c-bs
p=i+1;
q=j+1;
y(p:p+bs-1,q:q+bs-1)=(H')*x(p:p+bs-1,q:q+bs-1)*H;
end
end

n1=nnz(y);

z=y;
m=max(max(y));
y=y/m;
y(abs(y)<delta)=0; %replace too low value to zero.
y=y*m;
n2=nnz(y);

for i=0:bs:r-bs
for j=0:bs:c-bs
p=i+1;
q=j+1;
z(p:p+bs-1,q:q+bs-1)=H*y(p:p+bs-1,q:q+bs-1)*H';
end
end

rgb(:,:,j1)=z;

end
disp('block size:');bs
figure;
subplot(1,2,1)
imshow(uint8(in)),title('Original image');

subplot(1,2,2)
imshow(uint8(rgb)),title('Compressed image');
title('Haar Transformation - Image Compression');

% Find the error in pixel values
DIF=imsubtract(in,rgb);
mse=mean(mean(DIF.*DIF));
rmse=sqrt(mse);
rmse=(rmse(:,:,1)+rmse(:,:,2)+rmse(:,:,3))/3;
psnr=20*log(255/rmse);

comp_name='compressed_rgb.jpg'
imwrite(rgb,comp_name)

%% calculate Compression ratio
im_file=imfinfo(im_name);
input_file_sz=im_file.FileSize;
comp_file=imfinfo(comp_name);
comp_file_sz=comp_file.FileSize;

x=1/(nnz(im_name)/nnz(comp_name));
cr=input_file_sz/comp_file_sz;
filesz = [input_file_sz comp_file_sz cr];

fprintf('HAAR Transformation..');
fprintf('im_name: %s COMPRESSED_IMAGE_NAME: %s\n\n',im_name,comp_name)
formatSpec = 'INPUT FILE SIZE is %f, COMPRESSED FILE SIZE %f CR is %f\n\n';
fprintf(formatSpec,filesz)
ansrs = [rmse psnr];
formatSpec = 'RMSE is %f, PSNR is %f \n';
fprintf(formatSpec,ansrs)




Input Image :cameraman1.jpg





Image compression using HAAR Transformation Algorithm- Matlab code




Original Image size: 74.1 KB (75,936 bytes)





Output of program:





output-image-compression-haar-transform-matlab
Output Haar Transform Image Compression




Compressed image : compressed_haar.jpg





compressed_image_haar_transformation
compressed_image_haar_transformation
image size reduced to 54.3 KB 55,626 bytes




Results of matlab program of image compression using HAAR Transformation is





  • CR:1.365117
  • RMSE: 16.007825
  • PSNR: 55.363717
  • Original Image size: 74.1 KB (75,936 bytes)
  • Image size reduced to 54.3 KB (55,626 bytes)









Performance Metrics of Image compression





Compression Ratio (CR)





It is ratio between the uncompressed image (i.e original image) size and compressed image size.





Root Means Square Error (RMSE)





It is the difference between reconstructed image after compression and original image. It measure of quality of compression algorithm.





Lower the value of RMSE means better compression done by algorithm.





RMSE formula





RMSE IMAGE COMPRESSION FORMULA




Where N & M is the width and Height of image, X & Y represents reconstructed image and original image.





PSNR (Peak Signal to Noise Ratio)





It evaluates the approximate degree between raw image and processed image. This ratio is used to measure quality between the original and a compressed image.





The higher the PSNR, the better the quality of the compressed or reconstructed image.





psnr-peak-signal-to-noise-ratio-formula




Download Code:[download id="3172"]


How to Create a Course in Moodle? Step-by-Step Guide

How to Create a Course in Moodle? Step-by-Step Guide What is moodle? Moodle is a web based software deployed by Martin Dougiamas. Mood...