Monday, September 13, 2010

Black and white Image Water marking in spatial domain


Base Image After Watermarking


In this program the base image is a gray scale image and the water mark image is a black&white image. The water mark image will insert on any bit plain position that will be chosen by the chaotic random sequence. Before inserting the image the image will scrambled and inserted to the base image.

clear all; close all; clc;

tic;
f1 = imread('le.tif');
%f1 = imresize(f1,[64,64]);
%f1 = rgb2gray(f1);
[m n] = size(f1);
f=zeros(m,n);
for i=1:m
for j=1:n
if f1(i,j)>=128
f(i,j)=1;
end
end
end

f2=f;
figure,imshow(f1),title('Water Mark Image');
si1=m*n;
con =10;
rimg = f;
if m == n
while (con > 0)
for i =1:m
for j = 1:n
xva = mod((i+j),m);
if xva == 0
xva=m;
end
%XA(i,j) = xva;
yva = mod((i+(2*j)),m);
if yva == 0
yva=m;
end
%YA(i,j) = yva;
rimg(xva,yva) = f(i,j);
end
end
con = con-1;
f = rimg;
end
end
figure,imshow(f);
imwrite(f,'wat1.tif');
img = imread('cameraman.tif');
img = imresize(img,[256,256]);
[m1,n1]=size(img);
si=m1*n1;
Z=zeros(1,si1);
Z1=zeros(1,si1);
Zn=0.3; mu=3.5699456;
for i=1:(si1)
Z(i)=mu*Zn*(1-Zn);
Zn=Z(i);
if Zn >= 0.75
Z1(i)=7;
elseif Zn >= 0.5
Z1(i)=6;
elseif Zn >= 0.25
Z1(i)=5;
else
Z1(i)=4;
end
end
img1=img;
img2=img(:)';
f1=f(:)';
co=0;
%co1=1;co2=0;
for i=1:si1
S1=dec2bin(img2(i),8);
S3 = Z1(i);
S1(S3)=num2str(f(i));
img2(i)=bin2dec(S1);
end
res=reshape(img2,m1,n1);
figure,imshow(res);
imwrite(res,'water.tif');

Tuesday, August 3, 2010

Morphological opening in IDL

pro Mopening
; Handle TrueColor displays:
DEVICE, DECOMPOSED=0

;Read the image
path=FILEPATH('pollens.jpg',SUBDIR=['examples','demo','demodata'])
READ_JPEG, path, img

; Create window:
WINDOW, 0, XSIZE=700, YSIZE=540

;Show original image
XYOUTS, 180, 525, 'Original Image', ALIGNMENT=.5, /DEVICE
TV, img, 20, 280

;Apply the threshold
thresh = img GE 140B

;Load a simple color table
TEK_COLOR

;Display edges
XYOUTS, 520, 525, 'Edges', ALIGNMENT=.5, /DEVICE
TV, thresh, 360, 280

;Apply opening operator
open = MORPH_OPEN(thresh, REPLICATE(1,3,3))

;Show the result
XYOUTS, 180, 265, 'Opening Operator', ALIGNMENT=.5, /DEVICE
TV, open, 20, 20

;Show pixels that have been removed in white
XYOUTS, 520, 265, 'Removed Pixels in White', ALIGNMENT=.5, /DEVICE
TV, open + thresh, 360, 20
end

Hit or Miss operation in IDL

pro Mhotmiss
;Handle TrueColor displays:
DEVICE, DECOMPOSED=0

;Read the image
path=FILEPATH('pollens.jpg',SUBDIR=['examples','demo','demodata'])
READ_JPEG, path, img

WINDOW, 0, XSIZE=700, YSIZE=540

; Display the original image
XYOUTS, 180, 525, 'Original Image', ALIGNMENT=.5, /DEVICE
TV, img, 20, 280

rh = 2 ;Radius of hit disc
rm = 4 ;Radius of miss disc

;Create a binary disc of given radius.
hit = SHIFT(DIST(2*rh+1), rh, rh) LE rh

;Complement of disc for miss
miss = SHIFT(DIST(2*rm+1), rm, rm) GT rm

;Load discrete color table
TEK_COLOR

;Apply the threshold
thresh = img GE 140B

; Display the thresholded image
XYOUTS, 520, 525, 'Thresholded Image', ALIGNMENT=.5, /DEVICE
TV, thresh, 360, 280

;Compute matches
matches = MORPH_HITORMISS(thresh, hit, miss)

;Expand matches to size of hit disc
matches = DILATE(matches, hit)

;Show matches.
XYOUTS, 180, 265, 'Matches', ALIGNMENT=.5, /DEVICE
TV, matches, 20, 20

;Superimpose, showing hit regions in blue.
;(Blue = color index 4 for tek_color.)
XYOUTS, 520, 265, 'Superimposed, hit regions in blue',$
ALIGNMENT=.5, /DEVICE
TV, thresh + 3*matches, 360, 20
end

Image Resizing in IDL

Pro Image_Resizing
device,decompose=0
loadct,0
READ_JPEG,'C:\ITT\IDL64\examples\data\md1107g8a.JPG',im
sz=SIZE(im,/DIMENSIONS)
WINDOW,0,XSIZE=sz[0],YSIZE=sz[1],TITLE='IMAGE'
TV,im
sz1=sz*1.5 ; IMAGE SIZE
PRINT,SZ1
im1 = CONGRID(im,sz1[0],sz1[1],/interp) ; RESIZE THE IMAGE
WINDOW,1,XSIZE=sz1[0],YSIZE=sz1[1],TITLE='RESIZED_IMAGE'
TV,im1

end

RGB to NTSC Color Conversion in IDL

PRO rgbcolorconversion
file = FILEPATH('rose.jpg',SUBDIRECTORY = ['examples', 'data'])
queryStatus = QUERY_IMAGE(file, imageInfo)
PRINT, 'Query Status = ', queryStatus
HELP, imageInfo, /STRUCTURE
imageSize = imageInfo.dimensions
READ_JPEG,file,image
imageDims = SIZE(image, /DIMENSIONS)
; rgb to gray conversion
gimage=fltarr(imagedims[0],imagedims[1],imagedims[2])
CM=[[0.299, 0.587, 0.144],[0.596, -0.274, -0.322],[0.211, -0.523,0.312]]
for i=0,imagedims[1]-1 do begin
for j=0,imagedims[2]-1 do begin
V=image[*,i,j]
gimage[*,i,j]=CM * TRANSPOSE(V)
endfor
endfor

interleaving = WHERE((imageDims NE imageSize[0]) AND $
(imageDims NE imageSize[1])) + 1
PRINT, 'Type of Interleaving = ', interleaving
DEVICE, DECOMPOSED = 1
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $
TITLE = 'An RGB Image'
TV, image, TRUE = interleaving[0]
WINDOW, 1, XSIZE = imageSize[0], YSIZE = imageSize[1], $
TITLE = 'An NTSC Image'
TV, gimage, TRUE = interleaving[0]
end

Wavelet Transformation in IDL

PRO WAVELETTRANSFORM


READ_GIF,'d:\Image\bird.gif',f
sz=size(f,/dimensions)
DEVICE,DECOMPOSED = 0
LOADCT, 0
WINDOW,0,XSIZE=SZ[0],YSIZE=SZ[1],TITLE='Original Image'
tvscl, congrid(f,sz[0],sz[1])
f1 = wtn(f,20)
f2=abs(f1)^2
f2 = alog10(f2)
WINDOW,1,XSIZE=SZ[0],YSIZE=SZ[1],TITLE='Transformed Image'
tvscl, congrid(f2,sz[0],sz[1])
f3 = wtn(f1,20,/inverse)
WINDOW,2,XSIZE=SZ[0],YSIZE=SZ[1],TITLE='inverse Transformed Image'
tvscl, congrid(f3,sz[0],sz[1])

END

POWER SPECTRUM of IMAGES in IDL

PRO POWER_SPECTRUM_EX
im = [64,64]
file = FILEPATH('abnorm.dat',SUBDIRECTORY =['examples','data'])
f = READ_BINARY(file,DATA_DIM=im)
sz = 2*im
DEVICE, DECOMPOSED = 0
loadct, 0
f1 = FFT(f)
center = im/2 + 1
fs = SHIFT(F1,center)
ps = ABS(fs)^2
sps = ALOG10(ps)
WINDOW,0,XSIZE = SZ[0],YSIZE = SZ[1],TITLE = 'POWER SPECTRUM'
TVSCL,CONGRID(sps,sz[0],sz[1])
END