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

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.

Related

how to save the generated images from this code separated

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)

Why it does not showing the year value .in D3plus scatter?

I am using D3plus for data visualization . but in the x axis wrong data is showing instead of what i wrote in .x("year") to show .
http://jsfiddle.net/MituVinci/a77kz0dr/
enter code here
var visualization = d3plus.viz()
.container("#viz") // container DIV to hold the visualization
.data(sample_data) // data to use with the visualization
.type("scatter") // visualization type
.id("Reason") // key for which our data is unique on
.x("year") // key for x-axis
.y("Female") // key for y-axis
.draw()
I also want to resize the width and height of this and also want to show it using an external json file how can i do it ?
Since you have "Reason" as your .id() variable, D3plus is aggregating all data points that have the same "Reason". So the "x" position for "Family Feud" is 2010+2011+2012+2013+2014 or 10060, which is where all of your bubbles are located.
If you want to display each bubble individually, you could create a separate variable called "ReasonYear", concat the text of the Reason and Year fields together and then use .id("ReasonYear") for your visualization.
Use .width() and .height() to control the width and height respectively of your visualization.
Use .data() to load data from an external JSON file
Documentation can be found here: https://github.com/alexandersimoes/d3plus/wiki/Visualizations

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()

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);

Why does UMN-Mapserver shows an ERDAS Image-File (.img) as white shape?

I want to render an ERDAS-Image-file (suffix .img) with the UMN-Mapserver. The data is rendered on the right position and with the correct shape, but all data is white instead of an raster-image. The Image contains many layers. My mapfile looks like this:
MAP
NAME "Test"
WEB
METADATA
"wms_title" "test"
"WMS_SRS" "epsg:31466 epsg:31467 epsg:31468 epsg:31469 epsg:4326 epsg:25832 epsg:3035"
END
LOG "test.log"
IMAGEPATH "."
END
SHAPEPATH "."
PROJECTION
"init=epsg:32632"
END
LAYER
NAME "testlayer"
TYPE RASTER
DATA "test.img"
STATUS ON
OFFSITE 0 0 0
END
OUTPUTFORMAT
NAME png
DRIVER "GD/PNG"
MIMETYPE "image/png"
IMAGEMODE RGBA
END
END
To give an answer to my own question: The input-file had 16 Bit per channel and that didn't worked out. The mapserver can scale the colors, but you need the data from the people, that have knowledge about the image. In my case, I was said to scale from 0-22000, so I wrote the following line to the layer-definition:
PROCESSING "SCALE=0,22000"
That worked well, now I can see structure in the image. If you don't know about the correct scale, you could try the following
PROCESSING "SCALE=AUTO"
I hope this helps someone, who runs into the same trouble in the future.