Hiding data from a text file in a image file using dwt steganography - steganography

The code below hides the text "helloworld" in the two specified DWT coefficients using steganography. I have been trying to adapt the code to hide data contained in a .txt file. I have been working on this for a while but cant seem to get anything to work correctly. Can anyone help please?
clear all;
close all;
dataToHide = 'helloworld';
wavename = 'haar';
data = zeros(1,length (dataToHide));
for i =1 : length(dataToHide);
d = dataToHide (i)+0;
data (i) = d;
end
im=imread ('cameraman.tif');
%imshow(im);
[cA1, cH1,cV1, cD1]= dwt2(im,wavename);
A1 = upcoef2('a',cA1,wavename,1);
H1 = upcoef2('h',cH1,wavename,1);
V1 = upcoef2('v',cV1,wavename,1);
D1 = upcoef2('d',cD1,wavename,1);
subplot(2,2,1); image(wcodemat(A1,192));
title ('A1');
subplot(2,2,2); image(wcodemat(H1,192));
title ('H1');
M=max(data);
normilize = data/M;
n=length(data);
cH1 (1,1) = -1*(n/10);
cH1 (1,2) = -1*(M/10);
[~ , y] =size(cH1);
for i = 1 : ceil(n/2)
cV1 (i,y) = normilize(i);
end
for i= ceil(n/2)+1 :n;
cD1 (i,y) = normilize(i);
end
Update
I can know read text from the file.However, I have come across another problem. When I read from file I want to convert the text to binary (name=dec2bin(dataToHide). The above code doesn't want to hide binary data for me?? I am very new to matlab & steganography/watermarking. I have been doing lots of research regarding LSB embedding in the discrete wavelet transform. However, the code above, which I took from the web is manipulating subband coefficients, but from what I can read from the code it is not doing it by LSB replacement. (i.e replace LSB of cover image with MSB of the secret data file). Can anyone recommend some code for me to look at that works by LSb wavelets embedding?

Related

How to generate a fits file from the beginning

In this post, they explain how to generate a fits file from ascii file. However, I also would like to know how to define header and data into fits file. (Converting ASCII Table to FITS image)
For example, when I call a spectral fits file with astropy (which is downloaded from a telescope), I can call data and header separately.
I.E
In [1]:hdu = fits.open('observation.fits', memmap=True)
In [2]:header = hdu[0].header
In [3]:header
Out [3]:
SIMPLE = T / conforms to FITS standard
BITPIX = 8
NAXIS = 1
NAXIS1 = 47356
EXTEND = T
DATE = 'date' / file creation date (YYYY-MM-DDThh:mm:ss UT)
ORIGIN = 'XXX ' / European Southern Observatory
TELESCOP= 'XXX' / ESO Telescope Name
INSTRUME= 'Instrument' / Instrument used.
OBJECT = 'ABC ' / Original target.
RA = 30.4993 / xx:xx:xx.x RA (J2000) pointing
DEC = -20.0009 / xx:xx:xx.x DEC (J2000) pointing
CTYPE1 = 'WAVE ' / wavelength axis in nm
CRPIX1 = 0. / Reference pixel in z
CRVAL1 = 298.903594970703 / central wavelength
CDELT1 = 0.0199999995529652 / nm per pixel
CUNIT1 = 'nm ' / spectral unit
..
bla bla
..
END
In [3]:data = hdu[0].data
In [4]:data
Out [4]:array([ 1000, 1001, 1002, ...,
5.18091546e-13, 4.99434453e-13, 4.91280864e-13])
Lets assume, I have data like below
WAVE FLUX
1000 2.02e-12
1001 3.03e-12
1002 4.04e-12
..
bla bla
..
So, I'd like to generate a spectral fits file with my own data (with its own header).
Mini question : Now lets assume, I generate spectral fits file correctly, but I realised that I forgot to take logarithm of WAVE values in X axis (1000, 1001, 1002, ....) . How can I do that without touching FLUX values of Y-axis (2.02e-12, 3.03e-13, 4.04e-13) ?
FITS files are organized as one or more HDUs (Header Data Units) consisting, as the name suggests, as one data object (generally, a single array for an observation, though sometimes something else like a table), and the header of metadata that goes with that data.
To create a file from scratch, especially an image, the simplest way is to directly create an ImageHDU object:
>>> from astropy.io import fits
>>> hdu = fits.ImageHDU()
Just as with an HDU read from an existing file, this HDU has a (mostly empty) header, and an empty data attribute that you can then assign to:
>>> hdu.data = np.array(<some numpy array>)
>>> hdu.header['TELESCOP'] = 'Gemini'
When you're satisfied you can write the HDU out to a file with:
>>> hdu.writeto('filename.fits')
(Note: A lot of the documentation you'll see demonstrates a more complex process of creating an HDUList object, appending the HDU to the HDU list, and then writing the full HDU list. This is only necessary if you're creating a multi-extension FITS file. For a single HDU, you can use hdu.writeto directly and the framework will handle the other structural details.)
In general you don't need to manipulate the headers that describe the format of the data itself--that is automatic and should not be touched by hand (FITS has the unfortunate misfeature of mixing information about data structure with actual metadata). You can see more examples on how to manipulate FITS data here: http://docs.astropy.org/en/stable/generated/examples/index.html#astropy-io
Your other question pertains to manipulating the WCS (World Coordinate System) of the image, and in particular for spectral data this can be non-trivial. I would ask a separate question about that with more details about what you hope to accomplish.

Importing a TermDocumentMatrix into R

I am working on a qualitative analysis project in the tm package of R. I have built a corpus and created a term document matrix and long story short I need to edit my term document matrix and conflate some of its rows. To do this I have exported it out of R using
write.csv()
I then have imported the csv file back into R but am struggling to figure out how to get R to read it as a TermDocumentMatrix or DocumentTermMatrix.
I tried using the suggestions of the following example code with no avail.
It seems to keep reading my matrix as if it was a corpus and each cell as a single document.
# change this file location to suit your machine
file_loc <- "C:\\Documents and Settings\\Administrator\\Desktop\\Book1.csv"
# change TRUE to FALSE if you have no column headings in the CSV
x <- read.csv(file_loc, header = TRUE)
require(tm)
corp <- Corpus(DataframeSource(x))
dtm <- DocumentTermMatrix(corp)
Is there any way to import in a csv matrix that will be read as a termdocumentmatrix or documenttermmatrix without having R read the csv as if each cell is a document?
You're not reading documents, so skip the Corpus() step. This should work directly:
myDTM <- as.DocumentTermMatrix(x, weighting = weightTf)
For next time, consider saving the TDM object as .RData as this will not require conversion, and is also much more efficient.
If you want to keep the format of any data, I would recommend to use the save() function.
You can save any R objects into a .RData file. And when you want to retrieve the data, you can use the load() function.

Value of Numeric control in script, LabView

I am trying to control a KEITHLEY 2612A SourceMeter using labview. I have installed the appropriate drivers and I managed to connect to the instrument using VISA. Currently I am just experimenting with the scripting language, which the instrument uses.
Is it possible to use a Numeric Controller - a Knob for example - and use its value in the script to be loaded to the instrument? I don't have enough reputation points to add images.
EDIT
ON = 1
OFF = 0
function hello()
display.clear()
display.setcursor (1,7)
display.settext ("DONE :)")
end
smub.reset()
smub.source.output = ON
--Set the measurement integration time
smub.measure.nplc = 1
smub.measure.delay = 0.05
--Configure the reading buffers
smub.nvbuffer1.clear()
smub.nvbuffer1.appendmode = 1
smub.nvbuffer1.collecttimestamps = 1
smub.nvbuffer1.collectsourcevalues = 0
smub.nvbuffer1.fillmode = smub.FILL_ONCE
for i = 0, 0.5, 0.01 do
smub.source.levelv = i
reading = smub.measure.i (smub.nvbuffer1)
end
delay(5)
hello()
smub.source.output = OFF
delay(1)
display.clear()
display.setcursor(1,1)
display.settext(string.format("%g", smub.nvbuffer1[1]))
delay(5)
display.clear()
display.settext(string.format("%g", smub.nvbuffer1[50]))
Block diagram: http://i.imgur.com/pgu0ous.png
Front panel: http://i.imgur.com/DuHUdpo.png
LabVIEW has standard string manipulation primitives, and you can accomplish your goal by using string substitution: place a sentinel string in your script and replace it with the value from the knob.
Example
Here, I've used __BUFFER_NUMBER__ as a unique string in the Script Format input terminal. LabVIEW searches for that string and replaces it with the knob's current value.
Block diagram
You add the knob control, wire the value to the number-to-string VI (http://zone.ni.com/reference/en-XX/help/371361M-01/glang/number_to_fract_string/
), and wire that to the "Search and replace string VI" (http://zone.ni.com/reference/en-XX/help/371361M-01/glang/search_and_replace_string/) you search for the value in the script that you want to replace.

scilab : index in variable name loop

i would like to read some images with scilab and i use the function imread like this
im01=imread('kodim01t.jpg');
im02=imread('kodim02t.jpg');
im03=imread('kodim03t.jpg');
im04=imread('kodim04t.jpg');
im05=imread('kodim05t.jpg');
im06=imread('kodim06t.jpg');
im07=imread('kodim07t.jpg');
im08=imread('kodim08t.jpg');
im09=imread('kodim09t.jpg');
im10=imread('kodim10t.jpg');
i would like to know if there is a way to do something like below in order to optimize the
for i = 1:5
im&i=imread('kodim0&i.jpg');
end
thanks in advance
I see two possible solutions using execstr or using some kind of list/matrix
Execstr
First create a string of the command to execute with msprintf and then execute this with execstr. Note that in the msprintf conversion the right amount of leading zeros are inserted by %0d format specifier descbribed here.
for i = 1:5
cmd=msprintf('im%d=imread(\'kodim%02d.jpg\');', i, i);
execstr(cmd);
end
List/Matrix
This is probably the more intuitive option using a indexable container such as list.
// This list could be generated using msprintf from example above
file_names_list = list("kodim01t.jpg", "kodim02t.jpg" ,"kodim03t.jpg");
// Create empty list to contain images
opened_images = list();
for i=1:length(file_names_list)
// Open image and insert it at end of list
opened_images($+1) = imread(file_names_list[i]);
end

MATLAB: Resizing a figure properly

I have a figure that I would like to resize and afterwards print as a PDF.
Using something like
set(hFig, 'PaperUnits', 'centimeters')
set(hFig, 'PaperSize', [x_B x_H]);
works as long as I do not resize the figure too drastically. If I reduce the height then at some points the xlabel moves out of the figure. I have searched a lot but only found an solution to manually resize the underlying axes-object
scalefactor = 0.96;
movefactor = 0.82;
hAx = get(gcf,'CurrentAxes');
g = get(hAx,'Position');
% 1=left, 2=bottom, 3=width, 4=height
g(2) = g(2) + (1-movefactor)/2*g(4);
g(4) = scalefactor*g(4);
set(hAx,'Position',g);
I do not like this approach since I have to manually adjust the two factors.
Before printing I set the 'interpreter' to 'latex' of all text-objects (if that is of concern).
Printing is achieved using
print(hFig, '-dpdf', '-loose', 'test.pdf');
I hoped to loosen the bounding box by using '-loose'. Any help is highly appreciated!
edit:
It seems that really the interpreter (none, tex, latex) plays a role in this. I got inspired by this post here (http://stackoverflow.com/questions/5150802/how-to-save-plot-into-pdf-without-large-margin-around) and came up with this solution:
tightInset = get(gca, 'TightInset');
position(1) = tightInset(1);
position(3) = 1 - tightInset(1) - tightInset(3);
if strcmpi(x_Interpreter,'latex')
position(2) = tightInset(2)+ 1*tightInset(4);
position(4) = 1 - tightInset(2) - 2*tightInset(4);
else
position(2) = tightInset(2)+ 0*tightInset(4);
position(4) = 1 - tightInset(2) - 1*tightInset(4);
end
set(gca, 'Position', position);
This may not solve your problem completely (it may just help clean up your code), but I found the fig code in the file exchange to be helpful: it lets you easily set the exact size of figures without bordering white space.