Pages

Skin Color Block in Matlab

17 August 2014
%%%%%%%%%%%%%%% FIND SKIN COLOR BLOCKS %%%%

[L,lenRegions] = bwlabel(SN_fill,4);
AllDat  = regionprops(L,'BoundingBox','FilledArea');
AreaDat = cat(1, AllDat.FilledArea);
[maxArea, maxAreaInd] = max(AreaDat);

FaceDat = AllDat(maxAreaInd);
FaceBB = [FaceDat.BoundingBox(1),FaceDat.BoundingBox(2),...
    FaceDat.BoundingBox(3)-1,FaceDat.BoundingBox(4)-1];

aa=imcrop(rgb2gray(uint8(I)).*uint8(SN_fill),FaceBB);

%  figure,imshow(aa);
%  title('Identified Face');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Read more ...

Big Factorial Using Java..Source Code

15 December 2013

Big Factorial!!! Have a fun..........


import
java.math.BigInteger;

public class Factorial {

    public static void main(String[] shan) {

            BigInteger bigInteger =  BigInteger.valueOf(1);

            for (int i = 2; i <= 100; i++)    // calculate 100!
 
                      bigInteger = bigInteger.multiply(BigInteger.valueOf(i));
          
                      System.out.println(bigInteger);
           
            System.out.println("Length is: "+bigInteger.toString().length());
   
    }

}

The output :::

933262154439441526816992388562667004907159682643816214
685929638952175999932299156089414639761565182862536979
20827223758251185210916864000000000000000000000000

Length is: 158
Read more ...

public,protected,private and default access modifiers in java simple example

12 October 2013

package package1;


public class A {
    protected int a=10;
    private int b=12;
    public int c=14;
    int d=16;
    public void print(){
        System.out.println("Package1 and access A class");
        System.out.println("Protected variable ="+ a);
        System.out.println("Private variable ="+ b);
        System.out.println("Public variable ="+ c);
        System.out.println("Default variable ="+ d);
       
        A aa=new A();
       
        System.out.println("Protected variable ="+ aa.a);
        System.out.println("Private variable ="+ aa.b);
        System.out.println("Public variable ="+ aa.c);
        System.out.println("Default variable ="+ aa.d);
       
    }

}
//...............................................................................//
package package1;

public class B extends A{
    public void print(){

        System.out.println("Package1 and access B class");
        System.out.println("Protected variable ="+ a);
        //System.out.println("Private variable ="+ b);//Look Private is not accessible in class B
        System.out.println("Public variable ="+ c);
        System.out.println("Default variable ="+ d);
      
        A aa=new A();
      
        System.out.println("Protected variable ="+ aa.a);
        //System.out.println("Private variable ="+ aa.b);// Same things here
        System.out.println("Public variable ="+ aa.c);
        System.out.println("Default variable ="+ aa.d);
    }

}

//.................................................................................//
package package1;

public class C {
    public void print(){
        A cc=new A();
        System.out.println("Package1 and access C class");
    //    System.out.println("Protected variable ="+ a);
        //System.out.println("Private variable ="+ b);
    //    System.out.println("Public variable ="+ c);
    //    System.out.println("Default variable ="+ d);
      
        //A aa=new A();
      
        System.out.println("Protected variable ="+ cc.a);
    //    System.out.println("Private variable ="+ aa.b);
        System.out.println("Public variable ="+ cc.c);
        System.out.println("Default variable ="+ cc.d);
    }
}

//...............................................................//
package Package2;

import package1.A;
public class AA extends A{

    public void print(){
        System.out.println("Package2 and access AA class");
        System.out.println("Protected variable ="+ a);
    //    System.out.println("Private variable ="+ b);
        System.out.println("Public variable ="+ c);
        //System.out.println("Default variable ="+ d);
      
        A aa=new A();
      
    //    System.out.println("Protected variable ="+ aa.a);
    //    System.out.println("Private variable ="+ aa.b);
        System.out.println("Public variable ="+ aa.c);
    //    System.out.println("Default variable ="+ aa.d);
      
    }

}

//...................................................................//
package Package2;

import package1.A;

public class BB {
    public void print(){
        System.out.println("Package2 and access BB class");
    //    System.out.println("Protected variable ="+ a);
    //    System.out.println("Private variable ="+ b);
    //    System.out.println("Public variable ="+ c);
    //    System.out.println("Default variable ="+ d);
    //  
        A aa=new A();
      
    //    System.out.println("Protected variable ="+ aa.a);
    //    System.out.println("Private variable ="+ aa.b);
        System.out.println("Public variable ="+ aa.c);
    //    System.out.println("Default variable ="+ aa.d);
      
    }

}
Read more ...

Breath-First_search(BFS) Source Code using Queue

29 July 2013

 Implementation BFS algorithm using C++
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
#define M 10000
vector<int> edges[M];
vector<int> cost[M];

void Bfs(int n,int source)
{
  queue<int>Q;
  Q.push(source);;
  int taken[100]={0},distance[100];
  taken[source]=1;
  distance[source]=0;
  while(!Q.empty())
  {

      int u=Q.front();
      int a=edges[u].size();
      for(int i=0;i<a;i++)
      {
          int v=edges[u][i];
          if(!taken[v])
          {

              distance[v]=distance[u]+1;
              taken[v]=1;
              Q.push(v);
          }
      }
      Q.pop();
  }
  for(int i=1;i<=n;i++)
  {

      printf("%d to %d distance %d\n",source,i,distance[i]);
  }

}



int main()
{
    int N,E,i;
    int esize,source;
    scanf("%d%d",&N,&E);//how many nodes and edges
    for(i=1;i<=E;i++)
       {
           int x,y;
           scanf("%d%d",&x,&y);
           edges[x].push_back(y);
           edges[y].push_back(x);
           cost[x].push_back(1);
           cost[y].push_back(1);
       }
printf("plz enter source node:");
scanf("%d",&source);
       Bfs(N,source);
 
       return 0;
}


Read more ...

Breath-First-Search(BFS) Source Code without using Queue :)

29 July 2013
 Implementation BFS algorithm using C++
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define M 10000
vector<int> edges[M];
//vector<int> cost[M];                     // u can use it later

void Bfs(int n,int source)                  // number of nodes and source point(node)
{

    vector<int> v1,v2;             // declare 2 vector instead of queue
    v1.push_back(source);     
    int taken[100]={0};
    printf("Level 0 :: %d\n",source);
    for(int loop=1;loop<n;loop++)
    {

        printf("Level %d ::",loop);
        for(int i=0;i<v1.size();i++)
        {

            int u=v1[i];
            for(int j=0;j<edges[u].size();j++)
            {
                int v=edges[u][j];               // we found an edge from u to v
                if(!taken[v])                    // we can not go same node twice
                   { printf("%d ",v);          // just process
                    taken[v]=1;                // processed an edge and puts a tag
                    v2.push_back(v);         // where we found v1's node and push it v2
                }
            }
        }

        if(v2.empty())
        {puts("Empty");break;         // can not process any more
        }
        else{                                 // process again
            puts("");
            v1.clear();
            v1=v2;
            v2.clear();
        }
    }
}



int main()
{
    int N,E,i;
    int esize,source;                      // esize==edge size
    scanf("%d%d",&N,&E);       //how many nodes and edges
    for(i=1;i<=E;i++)
       {
           int x,y;
           scanf("%d%d",&x,&y);
           edges[x].push_back(y);
           edges[y].push_back(x);
          // cost[x].push_back(1);       // we can use it future
          // cost[y].push_back(1);        // we can use it future
       }
printf("plz enter source node:");
scanf("%d",&source);
       Bfs(N,source);
 
       return 0;
}
// i followed this code by shafayet's lecture....Thanks shafayet :)
Read more ...