12 Nisan 2018 Perşembe

GÖRÜNTÜ İŞLEME ÖDEV*


#!/usr/bin/python
# -*- coding: utf-8 -*-

#-----------------------------------------------------------------------------
# husonet
# Hüseyin Özdemir
# 03.03.2011
# 2 adet tanımlanmış eleman sayısı aynı olan matris çarpımını yapar
#------------------------------------------------------------------------------

if __name__ == '__main__':
    matris1      = [[1, 2, 3],[4, 5, 6]]
    matris2      = [[1, 2, 3],[4, 5, 6]]
    carpimMatris = []
    for mat2 in matris2:
        for eleman2 in mat2:
            for mat1 in matris1:
                for eleman1 in mat1:
                    carpimMatris.append(eleman1 * eleman2)
    print carpimMatris
 

>>> from numpy import *    # Numpy kütüphanesini ön alan adı eki olmadan ekliyoruz
>>> print(identity(3))     # birim köşegen matris
[[ 1.  0.  0.]
 [ 0.  1.  0.]
 [ 0.  0.  1.]]
>>> print(eye(3))          # birim köşegen matris
[[ 1.  0.  0.]
 [ 0.  1.  0.]
 [ 0.  0.  1.]]
>>> print(eye(3, k=1))     # köşegenin bir üst çapraza birim vektör ekleme
[[ 0.  1.  0.]
 [ 0.  0.  1.]
 [ 0.  0.  0.]]
>>> print(eye(3, k=-2))    # köşegenin iki alt çapraza birim vektör ekleme
[[ 0.  0.  0.]
 [ 0.  0.  0.]
 [ 1.  0.  0.]]
 
>>> print(diag([2,3,4], k=0))       # [2,3,4] dizisinden köşegen matris
[[2 0 0]
 [0 3 0]
 [0 0 4]]
>>> print(diag([2,3,4], k=1))       # aynı diziden bir üst köşegen matris
[[0 2 0 0]
 [0 0 3 0]
 [0 0 0 4]
 [0 0 0 0]]
>>>
>>> # üçlü bant matris oluşturma
>>> print(diag(ones(4),k=-1) + diag(2*ones(5),k=0) + diag(ones(4), k=1))
[[ 2.  1.  0.  0.  0.]
 [ 1.  2.  1.  0.  0.]
 [ 0.  1.  2.  1.  0.]
 [ 0.  0.  1.  2.  1.]
 [ 0.  0.  0.  1.  2.]]
  


>>> A = ones((4,4))    # 1'lerden oluşan matris
>>> x = ones(4)        # 1'lerden oluşan vektör
>>> b = A*x            # matrisin her bir sütununun x ile vektörel çarpımı
>>> print(b)
[[ 1.  1.  1.  1.]
 [ 1.  1.  1.  1.]
 [ 1.  1.  1.  1.]
 [ 1.  1.  1.  1.]]
>>> b = dot(A,x)      # lineer cebir çarpımı
>>> print(b)
[ 4.  4.  4.  4.]
 
>>> A = random.random((4,4))     # rastgele kare A matrisi
>>> print(A)
[[ 0.69769186  0.79776825  0.09984681  0.21271922]
 [ 0.05979394  0.72758335  0.0570817   0.59825989]
 [ 0.61698744  0.29374527  0.82004994  0.41084264]
 [ 0.02961924  0.86964469  0.63311203  0.82975882]]
>>> b = random.random(4)         # rastgele b vektörü
>>> print(b)
[ 0.20801453  0.81169016  0.84603751  0.74985329]<
>>>
>>> x = dot(linalg.inv(A), b)    # Ax=b çözümü olarak x=A^-1*b
>>> print(dot(A,x))              # bulduğumuz çözümün sağlamasını yapıyoruz (Ax=b)
[ 0.20801453  0.81169016  0.84603751  0.74985329]
 

 

6 Nisan 2018 Cuma

Goruntu Isleme Odev

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
static int sum =0;
struct Node{
    int data;
    struct Node *left, *right;
};
struct Node *addNode(struct Node *root,int data){
    if(root==NULL){
            struct Node *tmp=(struct Node *)malloc(sizeof(struct Node));
    tmp->data=Null;
    tmp->left=Null;
    tmp->right=NULL;
    return tmp;  
       
    }
    if(root->data<data){
        root->right=addNode(root->right,data);
    }
    else{
        root->left=addNode(root->left,data);
    }
    return root;
}
void print(struct Node *root){
    if(root){
        printf("%d",root->data);
        print(root->left);
         print(root->left);
       
    }
}
int minumum(struct Node *root){
    if(root->left==Null){
        return root->data;
    }
    return minumum(root->left);
}
int max(struct Node *root){
    if(root->right==Null){
        return root->data;
    }
    return max(root->right);
}

5 Nisan 2018 Perşembe

GORUNTU ISLEME CUMA GUNU ODEVI

class Tree
{
private TreeNode root;
int h1 = 0,h2=0;
public Tree()
{ 
root = null; 
}
public TreeNode getRoot()
{ 
return root; 
}



int dugumsayisi(TreeNode p)    //Ağaçtaki node sayısını bulur
{
if(p==null)return 0;
if(p.leftChild!=null)
{
h1=dugumsayisi(p.leftChild);
}
if(p.rightChild!=null)
{
h2=dugumsayisi(p.rightChild);
}
return(max(h1,h2)+1);
}


private int max(int h1, int h2) {
if(h1>h2)return h1;
return h2;
}


public void preOrder(TreeNode localRoot)    //Önce kök sonra left child
{                                           //Son olarak right child taranır
if(localRoot!=null)
{
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}
}

public void inOrder(TreeNode localRoot)     //Önce left child sonra kök
{                                           //Son olarak right child taranır
if(localRoot!=null)                       //Aynı zamanda ağacı sıralı bir şekilde yazar
{
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
}
}

public void postOrder(TreeNode localRoot)      //Önce left child
{                                              //Sonra right child
if(localRoot!=null)                          //Son olarak kök taranır
{   
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
}
}


public void insert(int yenidata)            //Ağaca eleman ekleme
{
TreeNode yeniNode = new TreeNode();
yeniNode.data = yenidata;
if(root==null)
root = yeniNode;
else
{
TreeNode current = root;
TreeNode parent;
while(true)
{
parent = current;
if(yenidata < current.data)
{
current = current.leftChild;
if(current==null)
{
parent.leftChild=yeniNode;
return;
}
} 
else
{
current = current.rightChild;
if(current==null)
{
parent.rightChild=yeniNode;
return;
}
}
}   
}
}



int derinlik(TreeNode root)              //Ağacın derinliğini hesaplama
{ 
if (root==null) 
{ 
return -1; 
} 
else { 
int lDepth = derinlik(root.getLeftChild()); 
int rDepth = derinlik(root.getRightChild());
if (lDepth > rDepth)
return(lDepth+1); 
else return(rDepth+1); 
} 
}




public int minValue() { 
return( minValue(root) ); 
} 

private int minValue(TreeNode node) { 
TreeNode current = node; 
while (current.getLeftChild() != null) { 
current = current.getLeftChild(); 
}
return(current.getData()); 
}





public int maxValue() { 
return( maxValue(root) ); 
} 


private int maxValue(TreeNode node) { 
TreeNode current = node; 
while (current.getRightChild() != null) { 
current = current.getRightChild(); 
}
return(current.getData()); 
}






static void lookup(TreeNode node, int target)    //Ağaçta arama
{ 
if (node == null) 
{ 
return; 
} 
else 
{ 
if (target == node.getData()) 
System.out.println(node.getData()+"bulundu"); 
else { 
if (target < node.getData()) lookup(node.getLeftChild(), target); 
else lookup(node.getRightChild(), target); 
} 
} 
}


public boolean isBST() {        //Ağaç ikili ağaç mı?
return(isBST(root)); 
}

private boolean isBST(TreeNode node) 
{ 
if (node==null) return(true);
if (node.leftChild!=null && maxValue(node.leftChild) > node.data) 
return(false); 
if (node.rightChild!=null && minValue(node.rightChild) <= node.data) 
return(false);
return( isBST(node.leftChild) && isBST(node.rightChild) ); 
} 


public boolean sameTree(Tree other) {      //İki ağaç eşit mi?
return( sameTree(root, other.root) ); 
}

boolean sameTree(TreeNode a, TreeNode b) 
{ 
if (a==null && b==null) 
return(true);
else if (a!=null && b!=null) 
{ 
return( a.data == b.data && 
sameTree(a.leftChild, b.leftChild) && 
sameTree(a.rightChild, b.rightChild) 
); 
} 
else return(false); 
} 

}