예제 #1
0
파일: test_epr.py 프로젝트: ydiazn/dhdicom
    def test_anonimization_sucess(self):
        import pydicom

        registers = ['PatientName', 'PatientID']
        recipe = os.path.join(self.base, 'recipes/confidential')
        handler = EPRData(registers, recipe)

        # Verifica que efectivamente la imagen original tiene
        # los registros PatientName y PatientID
        self.image.PatientName
        self.image.PatientID

        file, data = handler.anonimize(self.image)

        # Verifica la eliminación de dichos registros tras la anonimización
        ds = pydicom.read_file(file)
        with self.assertRaises(AttributeError):
            ds.PatientName
        with self.assertRaises(AttributeError):
            ds.PatientID

        # Verificacion de los valores de los registros extraidos
        self.assertDictEqual(data, {
            'PatientName': 'FRANCISCO^ALVARES^QUESAD',
            'PatientID': 'HCMC-18-5456'
        }, 'Error extracting confidential data from image')
예제 #2
0
    def test_not_authentic_image(self):
        from dhdicom.hidding.mixed import EPRHindingAndAuthentication
        import pydicom

        filename = os.path.join(self.base, 'images/2.dcm')
        image = DicomImage(filename)
        ds = pydicom.read_file(filename)

        dimesions = ds.Rows, ds.Columns

        registers = ['PatientName', 'PatientID']
        recipe = os.path.join(self.base, 'recipes/confidential')
        epr = EPRData(registers, recipe)
        hider = EPRHindingAndAuthentication('nuevaclave')

        handler = DHDicomHandler(data_handler=epr, hider_handler=hider)
        new_image = handler.process(image)

        # Image Tampering
        x = dimesions[0] - 1
        y = dimesions[1] - 1
        pixels = new_image.read()
        pixels[0][0] += 1
        pixels[x][y] += 1
        new_image.write(pixels)

        # Despues del procesamiento los pixeles se modificaron
        authentic, blocks_tampered = handler.authenticate(new_image)
        self.assertFalse(authentic)
        # image size: 255x255, block size:32x32, block num: 255
        np.testing.assert_array_equal(blocks_tampered, np.array([0, 255]))
예제 #3
0
파일: test_epr.py 프로젝트: ydiazn/dhdicom
    def test_load_all_data_success(self):

        registers = ['PatientName', 'PatientID']
        recipe = os.path.join(self.base, 'recipes/confidential')
        handler = EPRData(registers, recipe)
        data = handler.read(self.image)
        self.assertDictEqual(data, {
            'PatientName': 'FRANCISCO^ALVARES^QUESAD',
            'PatientID': 'HCMC-18-5456'
        }, 'Error extracting confidential data from image')
예제 #4
0
파일: test_epr.py 프로젝트: ydiazn/dhdicom
    def test_an_incorrect_register(self):
        from dhdicom.exceptions import RegisterNotFound

        registers = ['PatientName', 'PatientData']
        recipe = os.path.join(self.base, 'recipes/confidential')
        handler = EPRData(registers, recipe)
        data = handler.read(self.image)
        self.assertDictEqual(data, {
            'PatientName': 'FRANCISCO^ALVARES^QUESAD',
            'PatientData': None
        }, 'Error extracting confidential data from image')
예제 #5
0
    def test_authentic_image(self):
        from dhdicom.hidding.mixed import EPRHindingAndAuthentication

        filename = os.path.join(self.base, 'images/2.dcm')
        image = DicomImage(filename)

        registers = ['PatientName', 'PatientID']
        recipe = os.path.join(self.base, 'recipes/confidential')
        epr = EPRData(registers, recipe)
        hider = EPRHindingAndAuthentication('nuevaclave')

        handler = DHDicomHandler(data_handler=epr, hider_handler=hider)
        new_image = handler.process(image)

        authentic, *l = handler.authenticate(new_image)
        self.assertTrue(authentic)
        # No hay bloques modificados
        self.assertFalse(l)
예제 #6
0
    def test_get_message(self):
        from dhdicom.hidding.mixed import EPRHindingAndAuthentication
        import pydicom

        filename = os.path.join(self.base, 'images/2.dcm')
        image = DicomImage(filename)
        ds = pydicom.read_file(filename)

        registers = ['PatientName', 'PatientID']
        patient_name = ds.PatientName
        patient_id = ds.PatientID

        recipe = os.path.join(self.base, 'recipes/confidential')
        epr = EPRData(registers, recipe)
        data = epr.read(image)
        hider = EPRHindingAndAuthentication('nuevaclave')

        handler = DHDicomHandler(data_handler=epr, hider_handler=hider)
        new_image = handler.process(image)

        self.assertEqual(data, handler.get_epr(new_image))
예제 #7
0
    def __init__(self, parent=None):
        # inicializar el padre
        super(VentanaPrincipal, self).__init__(parent)
        # configurar la interfaz
        self.setupUi(self)

        self.original_image = None
        self.watermarked_image = None
        self.hiddenEPRTable.setHorizontalHeaderLabels(["Register", "Value"])
        self.eprTable.setHorizontalHeaderLabels(["Register", "Value"])
        self.actionAbrir.triggered.connect(self.Cargar_imagen)
        self.actionSalvar.triggered.connect(self.Salvar_imagen)
        self.actionCropping.triggered.connect(self.crop_image)
        self.btn_procesar.clicked.connect(self.Procesar_imagen)
        self.btnExtractAuthenticate.clicked.connect(self.analizar)
        self.init_canvas()

        # Registros EPR
        base = os.path.dirname(os.path.dirname(__file__))
        self.epr = EPRData(settings.EPR_TO_HIDE, settings.RECIPE_FILE)
        self.hider = EPRHindingAndAuthentication('nuevaclave')
예제 #8
0
def main():
    # Keys
    key = "Aslorent7N;fpr-y5"

    base = os.path.dirname(__file__)

    # Directory
    dir = "tests/dicom"
    if not os.path.exists(dir): os.makedirs(dir)

    try:
        root = Tk()
        filename = filedialog.askopenfilenames(
            parent=root, initialdir=dir, title='Please select a directory')
        # Load cover image (array)
        cover = DicomImage(filename[0])
    except Exception:
        raise ValueError("The image files were not loaded")

    root.destroy()

    # Creating matrix
    M_Metrics = []

    # Creating directory
    dir_dat_file = os.path.join("dhdicom", "static", "Results")
    if not os.path.exists(dir_dat_file): os.makedirs(dir_dat_file)
    dir_dat_file = os.path.join(dir_dat_file, filename[0].split("/")[-2])
    dir_dat_file = "%s_Results.dat" % dir_dat_file

    # Instance
    metr = Metrics()

    # Building stego images. Generating results
    for i in range(len(filename)):
        row = []
        # Generating keys
        key = utils.sha256_to_key_bin(key)
        image = DicomImage(filename[i])
        registers = ['PatientName', 'PatientID']
        recipe = os.path.join(base, 'recipes/confidential')
        epr = EPRData(registers, recipe)
        hider = EPRHindingAndAuthentication(key)
        handler = DHDicomHandler(data_handler=epr, hider_handler=hider)
        new_image = handler.process(image)
        cover_array = image.read()
        watermarked_array = new_image.read()
        # Experimental analysis
        row.append(metr.psnr(cover_array, watermarked_array))
        row.append(metr.uiqi(cover_array, watermarked_array))
        row.append(metr.image_fid(cover_array, watermarked_array))
        print(" ")
        print("Experimental analysis")
        print(" ")
        print("PSNR: ", row[0])
        print(" ")
        print("UIQI: ", row[1])
        print(" ")
        print("IF: ", row[2])
        print(" ")
        # Creating cols
        M_Metrics.append(row)
        # Saving results
        np.savetxt(dir_dat_file, M_Metrics, fmt="%.9e")

    # Saving results
    np.savetxt(dir_dat_file, M_Metrics, fmt="%.9e")