I am trying to create png images from dnd file for better understanding of dnd file.I have seen some software which convert dnd files to image format and I have around 2000 dnd file and I want to convert those file into image file for better understanding
Is it possible to create phylogenetic tree image from clusterw dnd file?
one example of the dnd file is like bellow:
(
(
A:0.336889,
(
(
B:0.204161,
(
(
(
C:0.112841,
(
D:0.0605849,
E:0.0605849):0.112841):0.133598,
(
F:0.0946236,
G:0.0946236):0.133598):0.148107,
H:0.148107):0.204161):0.285724,
I:0.285724):0.336889):0.338734,
J:0.338734):0.338734;
you may use ape library in R, dnd file is a type of Newick format
install.packages("ape")
library(ape)
MyTree <- read.tree("my_file.dnd")
png("my_file.png")
plot(MyTree)
dev.off()
you get:
or, if you prefer use phytools library, Note: before, you must first remove line breaks to input file
((A:0.336889,((B:0.204161,(((C:0.112841,(D:0.0605849,E:0.0605849):0.112841):0.133598,(F:0.0946236,G:0.0946236):0.133598):0.148107,H:0.148107):0.204161):0.285724,I:0.285724):0.336889):0.338734,J:0.338734):0.338734;
install.packages("phytools")
library(phytools)
MyTree <- read.newick("my_file.dnd")
png("my_file2.png")
plot(MyTree)
dev.off()
you get
Related
I have a code for simple line segmentation and I can segment the lines (non-overlapping lines), and I can display the lines using the command. Can anybody tell me how to save the lines as .jpg? The code segment for segmenting and displaying the line is shown below
for n=1:Ne
[r,c] = find(L==n);
n1=imagen(min(r):max(r),min(c):max(c));
% I want to save this line in this loop with filename.jpg ( in successive
% numbers like filename_1.jpg, filename_2.jpg and so on )
imshow(~n1);
%%pause(0.5)
pause(4)
end
I want to save the segmented line in this loop with filename.jpg ( in successive
numbers like filename_1.jpg, filename_2.jpg and so on )
Kindly suggest the command for the same
What i understood is you want to save the images with filename and numbered as filename_1.jpg You can write image as
str=strcat('filename_',num2str(n),'.jpg')
imwrite(n1,str)
imwrite(A,filename,fmt);
A is the image array you want to save, the filename is the output file and 'fmt' is the file format.
I have a matrix sig_matrix of data type double, the values are like:
3,0450 3,0450 3,0450
2,6200 2,6050 2,5900
2,5250 2,5200 2,5150
2,3800 2,3800 2,3650
2,6050 2,6650 2,7350
I need to save as an image file, but the problem is: image types like jpg, png only accepts integer data (uint8, uint16), but I really need to save the data as double.
I tried to save as a TIF file using the code below:
t = Tiff('test.tif', 'w8');
setTag(t,'Photometric',Tiff.Photometric.RGB);
setTag(t,'ImageLength',length(sig_matrix));
setTag(t,'ImageWidth',length(sig_matrix));
setTag(t,'BitsPerSample',64);
setTag(t,'SamplesPerPixel',3);
setTag(t,'SampleFormat', 3);
setTag(t,'PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
setTag(t,'Compression',Tiff.Compression.None);
write(t,repmat(sig_matrix, [1 1 3]));
close(t);
It worked, but then I tried to convert this file to yuv (using ffmpeg for example) but I got an error (Invalid TIFF header to be more specific).
So, I need to save a double matrix as a image file and then convert to yuv.
Anyone could help me please?
Obs.: I can't use mat2gray or something like that because I need that specific double data to convert to yuv
The background of my problem is that I want to extract the video data of Motion Photos (taken by my Samsung S7). Manually it is easy but time consuming. Just open the .jpg file in a HexEditor and extract all data after the line "MotionPhoto_Data". The first part is the image and the second part is the video.
My current code is
im = 'test.jpg'
with open(im, 'rb') as fin:
data = fin.read()
data_latin = data.decode('latin1')
fin.close()
position = data_latin.find('MotionPhoto_Data')
data_pic = data[:position]
data_mpg = data[position:]
My problem now is that I can´t figure out how to save these strings in a way that data_pic is saved as a working jpg and data_mpg as a working video.
I tried
with open('test_pic.jpg', 'a') as fin:
fin.write(str(data_pic))
fin.close()
But this didn´t worked. I think there is a basic issue on how I try to handle/save my data but I can´t figure out how to fix this.
I assume you use python 3 as it is tagged that way.
You should not decode with 'data.decode('latin1'). It is binary data.
data = fin.read()
Then later write it also as binary data:
with open('test_pic.jpg', 'ab') as fout:
fout.write(data_pic)
fout.close()
I know that it is possible to load all files of type .gif by using:
files = dir('C:\myfolder\*.gif');
However, my problem is that I want to load all files of type .gif and .jpg. What would be a good way of doing this?
You can simply search for both .gif and .jpg files then load and process the images one by one.
Just invoke dir twice - one for each type of image and store the results in two separate structures. Next, concatenate all of the file names to one structure, then go ahead and do your processing for all of the images.
Something like this:
%// Specify the folder where your images are stored
folder = fullfile('path', 'to', 'your', 'folder');
%// Specify search pattern for JPEG and GIF files
jpgFileFolder = fullfile(folder, '*.jpg');
gifFileFolder = fullfile(folder, '*.gif');
%// Invoke dir for both types of images
d1 = dir(jpgFileFolder);
d2 = dir(gifFileFolder);
%// Concatenate both dir structures together into a single structure
d = [d1; d2];
%// For each image we have...
for idx = 1 : numel(d)
%// Get full path to file
f = fullfile(folder, d(idx).name);
%// Read in the image
im = imread(f);
%// Do something with this image
%//...
%//...
end
fullfile allows you to create a directory string that is OS independent. Simply take each subdirectory that is part of your string and place them as separate string arguments into fullfile and it should work fine.
I have a folder of jpg files and I want to make them into a movie. I am using this script:
% Create video out of list of jpgs
clear
clc
% Folder with all the image files you want to create a movie from, choose this folder using:
ImagesFolder = uigetdir;
% Verify that all the images are in the correct time order, this could be useful if you were using any kind of time lapse photography. We can do that by using dir to map our images and create a structure with information on each file.
jpegFiles = dir(strcat(ImagesFolder,'\*.jpg'));
% Sort by date from the datenum information.
S = [jpegFiles(:).datenum];
[S,S] = sort(S);
jpegFilesS = jpegFiles(S);
% The sub-structures within jpegFilesS is now sorted in ascending time order.
% Notice that datenum is a serial date number, for example, if you would like to get the time difference in hours between two images you need to subtract their datenum values and multiply by 1440.
% Create a VideoWriter object, in order to write video data to an .avi file using a jpeg compression.
VideoFile = strcat(ImagesFolder,'\MyVideo');
writerObj = VideoWriter(VideoFile);
% Define the video frames per second speed (fps)
fps = 1;
writerObj.FrameRate = fps;
% Open file for writing video data
open(writerObj);
% Running over all the files, converting them to movie frames using im2frame and writing the video data to file using writeVideo
for t = 1:length(jpegFilesS)
Frame = imread(strcat(ImagesFolder,'\',jpegFilesS(t).name));
writeVideo(writerObj,im2frame(Frame));
end
% Close the file after writing the video data
close(writerObj);
(Courtesy of http://imageprocessingblog.com/how-to-create-a-video-from-image-files/)
But it gives me this error:
Warning: No video frames were written to this file. The file may be invalid.
> In VideoWriter.VideoWriter>VideoWriter.close at 289
In Movie_jpgCompilation at 37
I'm sure my jpg files are fine, and they are in the folder I specify. What is the problem?
(This is my first post ever, so I hope it helps).
If you're on Linux, don't the backslashes need to be forward slashes? When I ran it on my Mac, my jpegFiles was an empty Struct. When I changed them around it worked:
% Create video out of list of jpgs
clear
clc
% Folder with all the image files you want to create a movie from, choose this folder using:
ImagesFolder = uigetdir;
% Verify that all the images are in the correct time order, this could be useful if you were using any kind of time lapse photography. We can do that by using dir to map our images and create a structure with information on each file.
jpegFiles = dir(strcat(ImagesFolder,'/*.jpg'));
% Sort by date from the datenum information.
S = [jpegFiles(:).datenum];
[S,S] = sort(S);
jpegFilesS = jpegFiles(S);
% The sub-structures within jpegFilesS is now sorted in ascending time order.
% Notice that datenum is a serial date number, for example, if you would like to get the time difference in hours between two images you need to subtract their datenum values and multiply by 1440.
% Create a VideoWriter object, in order to write video data to an .avi file using a jpeg compression.
VideoFile = strcat(ImagesFolder,'/MyVideo.avi');
writerObj = VideoWriter(VideoFile);
% Define the video frames per second speed (fps)
fps = 1;
writerObj.FrameRate = fps;
% Open file for writing video data
open(writerObj);
% Running over all the files, converting them to movie frames using im2frame and writing the video data to file using writeVideo
for t = 1:length(jpegFilesS)
Frame = imread(strcat(ImagesFolder,'/',jpegFilesS(t).name));
writeVideo(writerObj,im2frame(Frame));
end
% Close the file after writing the video data
close(writerObj);
Edit: You can also use filesep so that the file separator is OS-specific. http://www.mathworks.com/help/matlab/ref/filesep.html
It would be simpler to use Windows Movie Maker [windows] or iMovie [mac]. For your purposes though you should use PowerPoint.