how to save the generated images from this code separated - deep-learning

I have run StarGAN Code from github, this code generate all the generated images in one picture.
How I can save all the generated images separated to single folder? I do not want to save all the images in one picture.
this is how it generate the output (sample image
I want to save the generated images from the trained model, not as samples with all the images in one picture but just a file that contains all the generated images.
This is the part of the code i want to change it
# Translate fixed images for debugging.
if (i+1) % self.sample_step == 0:
with torch.no_grad():
x_fake_list = [x_fixed]
for c_fixed in c_fixed_list:
x_fake_list.append(self.G(x_fixed, c_fixed))
x_concat = torch.cat(x_fake_list, dim=3)
sample_path = os.path.join(self.sample_dir, '{}-images.jpg'.format(i+1))
save_image(self.denorm(x_concat.data.cpu()), sample_path, nrow=1, padding=0)
print('Saved real and fake images into {}...'.format(sample_path))

The generator self.G is called on each element of c_fixed_list to generate images. All results are concatenated, then saved using torchvision.utils.save_image.
I don't see what's holding you from saving the images inside the loop. Something that would resemble:
for j, c_fixed in enumerate(c_fixed_list):
x_fake = self.G(x_fixed, c_fixed)
for k in range(len(x_fake)):
sample_path = os.path.join(self.sample_dir, f'{i+1}-{k}-feat{j}-image.jpg')
save_image(self.denorm(x_fake.data[k].cpu()), sample_path, nrow=1, padding=0)

Related

Cropping a TIFF to a ShapeFile/2

Regarding this:
Cropping a TIFF to a ShapeFile
I have an issue to fix regarding the code sahred at the link above. In the tiffs directory at the end, I can find only one cropped file, namely the last file in the directory? While instead I have 36 .tif files that have to be cropped.
This is the code:
crop_extent = gpd.read_file("path.shp")
extension = 'tif'
filenames = [i for i in glob.glob('path/*.
{}'.format(extension))]
tiffs = [rxr.open_rasterio(f) for f in filenames]
for tiff_name in filenames:
raster = rxr.open_rasterio(tiff_name)
assert crop_extent.crs == raster.rio.crs, "diffrent crs"
tiff_clipped =
raster.rio.clip(crop_extent.geometry.apply(mapping),
crop_extent.crs)
tiff_clipped.rio.to_raster(tiff_name + 'cropped.tif')
clipped_chm = rxr.open_rasterio(tiff_name +'cropped.tif')
Therefore, I would need an help to get the cropping over all the .tif files in the directory and not only last one.

How to avoid sikuli creating a png file when using "with Region"

I have the following code in sikulix (version 2015-01-06)
...
t = wait("total_power.png")
area = Region(t.x+t.w, t.y, 80, 31)
with Region(area):
wait("num_1.png")
....
I find that "with Region" will create a png file in the same directory of the python file. And the png file is the region that I want.
How can I avoid it?
What is is it that you are trying to do here?
Is it that you would like to wait until a window appears, and then look inside that window for another picture to appear?
In that case you alreay have defined the region when you found "t".
"t" is the location of the picture "total_power.png"
For example:
# Wait until the window appears.
p1 = wait("image1.png")
# Find another picture inside the window.
p2 = p1.wait("image2.png")
Edit:
You should have a look here: Link
I think you could use the .right(), if you leave the () empty you take everything.
If fill in a a value you take a part of the screen.
I use .hightlight() when programming to show me what region I am looking at.
You can also use region1.union(region2) to merge 2 region to a new one.
An example:
Image1 = ("image1.png")
class Blue():
def __init__(self):
# Find an image.
LocImage1 = find(Image1)
# Too show the user the region we selected, we can highlight if for 5 seconds.
LocImage1.highlight(5)
# Grab the region to the right of this image.
LocImage1RightSide = LocImage1.right()
# Highlight the region again.
LocImage1RightSide.highlight(5)
# Run class
Blue()

Read all images in one column, include the base64 string result to image html tag. XPage

as you can see the code below it can translate the image data from lotus database to a base64 string. The problem is I manually put the file name of the image (line 4). I have a lots of images on my database and only my "btnbg.jpg" can read it, the others are not. How can my code can read all the image file names inside the database column. Also how can I include the result base64 string to my html image tag. Thank you so much and God bless
var testView:NotesView = database.getView("uploadforms");
var col:NotesDocumentCollection = testView.getAllDocumentsByKey("1");
var testDoc:NotesDocument = col.getFirstDocument();
var attachment:NotesEmbeddedObject = testDoc.getAttachment("btnbg.jpg");
var input:java.io.InputStream = attachment.getInputStream();
var base64Enc = new sun.misc.BASE64Encoder();
var output = new java.io.ByteArrayOutputStream();
base64Enc.encode( input, output );
return output.toString();
"How can my code can read all the image file names inside the database column"
You need to print attachment names in to the column. For example with the help of "#AttachmentNames" function.
You need o use "ViewNavigator" class to traverse column exactly
If you are prefer to work with document, then use some of the methods go get all attachment from document, like "EmbeddedObjects" method on the document and RT items.
"how can I include the result base64 string to my html image tag"
You could do it with the help of css: background:url(data:image/jpeg;base64,...
It's a bad idea to use a lot of pictures in the css base64.

Imwrite command didn't create an image with true value in Matlab

I'm trying to write .tif image. I wrote the following command either on command window or within function file in Matlab to write tif image with the name of 'A_exam'.
All value of output image (A_exam.tif) are 255, no image displayed, just white screen. A matrix is extracted from following code. When I calculated this code, values of A matrix are correct. The problem just comes from writing an image file.
[~,Ind_max] = max(vgt,[],3);
A= arrayfun(#(y) ...
arrayfun(#(x) emp(x,y, Ind_max(x,y)), 1:size(vgt,1)), ...
1:size(vgt,2), 'UniformOutput',false);
A = reshape([A{:}], size(Ind_max))
imwrite(A,'A_exam.tif','tif')
Thank you
whos A
Name Size Bytes Class Attributes
A 41x41 6724 single
That reshape before calling imwrite looks problematic. I would change the
imwrite(A,'A_exam.tif','tif')
to add a call to mat2gray
imwrite(mat2gray(A),'A_exam.tif');
to make sure you're not mixing matrices and images.

In Matlab, I need a function/script that reads the element ij in two different images and outputs a new image which is the output of a function

Pretty simple:
I need a script that reads the element ij of TWO images (same size). These two elements will be the input of a function that I have (actually a fuzzy logic system). I want the output of this function to form a new image, this one is made with the output of my function for every ij element of the TWO images opened before.
Thanks very much!
Rodrigo
The naive approach:
sz = size(img1);
out = zeros(sz,class(img1));
for i=1:sz(1)
for j=1:sz(2)
out(i,j) = myFunc(img1(i,j), img2(i,j));
end
end
If your function is properly vectorized, you can just do:
out = myFunc(img1,img2);