File: imabsdiff.sci

package info (click to toggle)
sivp 0.4.3-3
  • links: PTS, VCS
  • area: contrib
  • in suites: lenny
  • size: 4,400 kB
  • ctags: 94
  • sloc: sh: 8,731; xml: 3,173; ansic: 2,069; makefile: 102; tcl: 72
file content (66 lines) | stat: -rw-r--r-- 2,395 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
////////////////////////////////////////////////////////////
// SIVP - Scilab Image and Video Processing toolbox
// Copyright (C) 2006  Shiqi Yu
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
////////////////////////////////////////////////////////////

function [imdiff] = imabsdiff(im1, im2)

    //check the image width and height
    if( or( size(im1)<>size(im2) )) then
	error("The two images do not have the same size or the same channel number.");
	//return;
    end
  
    if (size(size(im1),2)>3) then
	error("The two inputs are not images");
	return;
    end
    if (size(size(im1),2)==3) then
        if (size(im1, 3)<>1) & (size(im1,3)<>3) then
	    error("The two inputs are not images");
	    //return;
        end	    
    end

    //must be the same class, and not be uint32
    if (type(im1(1))<>type(im2(1)) | ...
      typeof(im1(1))<>typeof(im2(1)) | ...
      typeof(im1(1))=='uint32'   ) then
      error("The two input images must be of the same class and not be"+...
	     " uint32.");
    end

    //actruely abs(im1-im2) will be more efficient,
    //but abs(uint8(8)-uint8(9)) 
    //and abs(int16(2^15-1)-int16(-1))  will give error results 
    //(255 and -32768 respectively)
    //so we have to use OpenCV cvAbsDiff function for the same type at
    //these situations

    //int8 is not supported by OpenCV function cvAbsDiff
    //convert to int16 first when int8 class
    if ( typeof(im1(1))=='constant') then //double
       imdiff = abs(im1 - im2); 
    elseif ( typeof(im1(1))=='int8') then //int8
       imdiff = abs(int16(im1) - int16(im2));
       imdiff(imdiff > 127) = int16(127);
       imdiff = int8(imdiff);
    else 
       imdiff = int_imabsdiff(im1, im2);
    end

endfunction