% =================================================================
% == ==
% == An Introduction to ARTIFICIAL INTELLIGENCE ==
% == Janet Finlay and Alan Dix ==
% == UCL Press, 1996 ==
% == ==
% =================================================================
% == ==
% == chapter 8, pages 166-167: thresholding ==
% == ==
% == Prolog example, Alan Dix, September 1997 ==
% == ==
% =================================================================
% The files 'image.p' and 'gimage.p' describe the image representations
% used in this file and predicates to manipulate them..
% Uses:
% image_at/4 from file 'image.p'
% gimage_to_image/2 from file 'gimage.p'
% Please:
% consult('../util/meta.p'). % used by 'gimage.p'
% consult('../util/list.p'). % used by 'meta.p'
% consult('image.p').
% consult('gimage.p').
threshold_pixel( Pixel, Thresh, 0 ) :- Pixel < Thresh, !.
threshold_pixel( Pixel, Thresh, 1 ).
threshold_at( Input, Thresh, X, Y, Out_Pix ) :-
image_at( Input, X, Y, In_Pix ),
threshold_pixel( In_Pix, Thresh, Out_Pix ).
threshold_image( Input, Thresh, Wid, Ht, Output ) :-
gimage_to_image( ( (X,Y,P), (Wid,Ht),
threshold_at(Input,Thresh,X, Y, P) ),
Output ).
% RUNNING THIS CODE
%
% The file 'eximages.p' contains example images from all the figures
% in chapter 9. In particular, it has the pixel image used in the
% thresholding example in figure 8.2 on page 166.
% Consult this file:
% consult('eximages.p').
% Then try the following to replicate this example:
%> image('figure 8.2', Wid, Ht, Image),
%+ threshold_image( Image, 5, Wid, Ht, Output ).
% Try it with different threshold values.