encrypting a dicom image?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
i have the following code for encryption and decryption of .tif image. please help me to modify the samee for dicom images. when running with dicom following error is displayed as Error using ==> bitxor Inputs must be unsigned integers of the same class or scalar doubles.
Error in ==> processing at 16
proImage(ind1,ind2) = bitxor(Img(ind1,ind2),Fkey(ind1,ind2));
code
main function
clc;
close all;
clear all;
Img=imread('cameraman.tif');
%figure,imshow(Img);
%Img = dicomread('188.dcm');
figure,imshow(Img,[])
%figure,imshow(Img)
title('input image');
[n m k] = size(Img);
key = keyge(n*m);
EncImg = processing(Img,key);
figure,imshow(EncImg)
title('ecrypted');
imwrite(EncImg,'Encoded.jpg','jpg');
dec= processing(EncImg,key);
figure,imshow(dec)
title('decoded');
processing function
function [proImageOut] = processing(ImgInp,key)
[n m k] = size(ImgInp);
% key =cell2mat(struct2cell( load('key5.mat')));
% key = keyGen(n*m);
for ind = 1 : m
Fkey(:,ind) = key((1+(ind-1)*n) : (((ind-1)*n)+n));
end
len = n;
bre = m;
for ind = 1 : k
Img = ImgInp(:,:,ind);
for ind1 = 1 : len
for ind2 = 1 : bre
proImage(ind1,ind2) = bitxor(Img(ind1,ind2),Fkey(ind1,ind2));
end
end
proImageOut(:,:,ind) = proImage(:,:,1);
end
% figure,imshow(proImageOut);
return
key
function [key] = key(n)
n = n*8;
% n = 2048*2048*16;
% n = 24 * 24 * 8;
bin_x = zeros(n,1,'uint8');
r = 3.9999998;
bin_x_N_Minus_1 = 0.300001;
x_N = 0;
tic
for ind = 2 : n
x_N = 1 - 2* bin_x_N_Minus_1 * bin_x_N_Minus_1;
if (x_N > 0.0)
bin_x(ind-1) = 1;
end
bin_x_N_Minus_1 = x_N;
end
toc
% save bin_sec bin_x;
t = uint8(0);
key = zeros(n/8,1,'uint8');
for ind1 = 1 : n/8
for ind2 = 1 : 8
key(ind1) = key(ind1) + bin_x(ind2*ind1)* 2 ^ (ind2-1);
end
end
0 Kommentare
Antworten (1)
Walter Roberson
am 13 Dez. 2015
What does
dicominfo('188.dcm')
show for BitDepth ? I suspect you will find that it returns 16 for your file -- that is, that your DICOM image is uint16() where your code is expecting it will be uint8(). You will need to decide how you want to handle the situation.
2 Kommentare
Walter Roberson
am 13 Dez. 2015
Replace
for ind = 1 : m
Fkey(:,ind) = key((1+(ind-1)*n) : (((ind-1)*n)+n));
end
with
for ind = 1 : m
Fkey(:,ind) = cast( key((1+(ind-1)*n) : (((ind-1)*n)+n)), class(ImgInp) );
end
Siehe auch
Kategorien
Mehr zu DICOM Format finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!