Photoshop JSX font size - font-size

UPD: I am using Photoshop CC 5
I am writing a script for replacing strings in Psd text layers. Everything works fine, except that in some of those layers the text size is significantly smaller than that of the original strings. When I log the text size before and after I change the contents, they are indeed different:
The old size and new size: 74.601448059082 pt : 38.3819046020508 pt
I tried saving the old size in a var and then setting the size after I change the content, but the text size is still wrong (and equal to that second value). What am I doing wrong?
Here is the code I use for replacing the string and logging:
var originalString = layerSet.textItem.contents;
var replacementString = "";
replacementString = mmiFromLines(originalString, lines);
var oldSize = layerSet.textItem.size;
var oldKind = layerSet.textItem.kind;
layerSet.textItem.contents = replacementString;
log.writeln("The old size and new size: " + oldSize.value + " " + oldSize.type + " : " + layerSet.textItem.size.value + " " + layerSet.textItem.size.type);
log.writeln("Old kind vs new kind: " + oldKind + " : " + layerSet.textItem.kind);
layerSet.textItem.size = new UnitValue(oldSize.value, oldSize.type);
log.writeln("The new text size in the layer: " + layerSet.textItem.size.value + " " + layerSet.textItem.size.type);
log.writeln("_____________________________________________");

Related

How to hdf5 (Hdfsl ) file (One Column Read) read (Big Size file)

I am using the HDF5DotNet with C# and I can read only full data as the attached image in the dataset.
The hdf5 file is too big, up to nearly 1.4GB, and if I load the whole array into the memory then it will be out of memory.
I would like to read all data from One columns
double[] values = new double[203572];
string m_Doc_01 = "data/sample/line";
HDFql.Execute("USE DIRECTORY " + "\"" + File_Directory + "\"");
HDFql.Execute("USE FILE " + "\"" + File_Name + "\"");
HDFql.Execute("CREATE CHUNKED(1, 203572) DATASET my_dataset_BS AS DOUBLE(2050, 203572)");
How to "m_Doc_01 ==> my_dataset_BS" Data
???
???
for (int i = 0; i < 2050; i++)
{
HDFql.Execute("SELECT FROM " + "\"" + m_Doc_01 + "\"" + "(1:::1) INTO MEMORY " + HDFql.VariableRegister(values));
}
To read the column that you have highlighted in the screenshot (i.e. column #0), you have to change the hyperslab to (please note the 0):
HDFql.Execute("SELECT FROM " + "\"" + m_Doc_01 + "\"" + "(, 0:::1) INTO MEMORY " + HDFql.VariableRegister(values));
That said, if you want to loop through the dataset and read one column at the time do the following (also better to register variable values before the loop starts and unregister it after the loop is done - this will increase performance):
number = HDFql.VariableRegister(values);
for(int i = 0; i < 2050; i++)
{
HDFql.Execute("SELECT FROM " + "\"" + m_Doc_01 + "\"" + "(, " + i + ":::1) INTO MEMORY " + number);
// do something with variable "values" (which contains the values of column #i)
}
HDFql.VariableUnregister(values);

MVC 5 Get Exif data for Camera make

I am trying to Get Exif data for Camera make, ISO speed etc. in a file upload. I can get some tags (see below) but need some guidance on extracting items from the Exif directories. Any suggestions please.
IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(strFileName);
foreach (var directory in directories)
foreach (var tag in directory.Tags)
System.Diagnostics.Debug.WriteLine(string.Format("Directory " + $"{directory.Name} - {tag.Name} = {tag.Description}"));
var subIfdDirectory = directories.OfType<ExifSubIfdDirectory>().FirstOrDefault();
var dateTime = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagDateTime);
System.Diagnostics.Debug.WriteLine(string.Format("dateTime " + dateTime));
//
Image img = Image.FromFile(strFileName);
ImageFormat format = img.RawFormat;
System.Diagnostics.Debug.WriteLine("Image Type : " + format.ToString());
System.Diagnostics.Debug.WriteLine("Image width : " + img.Width);
System.Diagnostics.Debug.WriteLine("Image height : " + img.Height);
System.Diagnostics.Debug.WriteLine("Image resolution : " + (img.VerticalResolution * img.HorizontalResolution));
System.Diagnostics.Debug.WriteLine("Image Pixel depth : " + Image.GetPixelFormatSize(img.PixelFormat));
PropertyItem[] propItems = img.PropertyItems;
int count = 0;
ArrayList arrayList = new ArrayList();
foreach (PropertyItem item in propItems)
{
arrayList.Add("Property Item " + count.ToString());
arrayList.Add("iD: 0x" + item.Id.ToString("x"));
System.Diagnostics.Debug.WriteLine("PropertyItem item in propItems: " + item.Id.ToString("Name"));
count++;
}
ASCIIEncoding encodings = new ASCIIEncoding();
try
{
string make = encodings.GetString(propItems[1].Value);
arrayList.Add("The equipment make is " + make.ToString() + ".");
}
catch
{
arrayList.Add("no Meta Data Found");
}
ViewBag.listFromArray = arrayList;
return View(await db.ReadExifs.ToListAsync());
}
Two loops I know, messy but gives some output :
Directory JPEG - Compression Type = Baseline
Directory JPEG - Data Precision = 8 bits
Directory JPEG - Image Height = 376 pixels
Directory JPEG - Image Width = 596 pixels
Directory JPEG - Number of Components = 3
Directory JPEG - Component 1 = Y component: Quantization table 0, Sampling factors 2 horiz/2 vert
Directory JPEG - Component 2 = Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert
Directory JPEG - Component 3 = Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert
Directory JFIF - Version = 1.1
Directory JFIF - Resolution Units = inch
Directory JFIF - X Resolution = 120 dots
Directory JFIF - Y Resolution = 120 dots
Directory JFIF - Thumbnail Width Pixels = 0
Directory JFIF - Thumbnail Height Pixels = 0
Directory File - File Name = FakeFoto03_large.Jpg
Directory File - File Size = 66574 bytes
Directory File - File Modified Date = Tue Jan 03 00:02:00 +00:00 2017
Image Type : [ImageFormat: b96b3cae-0728-11d3-9d7b-0000f81ef32e]
Image width : 596
Image height : 376
Image resolution : 14400
Image Pixel depth : 24
Thanks. Y.
If the image you're processing has camera make, ISO and so forth, the metadata-extractor will print it out. The image you're providing must not have those details.
Solved. This block:
ArrayList arrayList = new ArrayList();
IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(strFileName);
foreach (var directory in directories)
foreach (var tag in directory.Tags)
// System.Diagnostics.Debug.WriteLine(string.Format("Directory " + $"{directory.Name} - {tag.Name} = {tag.Description}"));
arrayList.Add($"{tag.Name} = {tag.Description}");
ViewBag.listFromArray = arrayList;
return View(await db.ReadExifs.ToListAsync());
This produces (in the case of the Photo used as source) 120 exif tags. Sample:
White Balance Mode = Auto white balance
Digital Zoom Ratio = 1
Focal Length 35 = 28 mm
Scene Capture Type = Standard
Gain Control = Low gain up
Contrast = None
Thanks to Drew for the reply, works fine now, up to a point. while the snippet prints to screen fine ( 160 items ), I cannot assign the items description to a variable or array. Here is the code:
// start exif ###############################
var strFileName = Server.MapPath("~/uploads/" + fname + "_large" + extension);
System.Diagnostics.Debug.WriteLine(">>> ReadExifsController, fname: " + fname);
if (System.IO.File.Exists(strFileName))
{
System.Diagnostics.Debug.WriteLine(">>> ReadExifsController File exists.");
}
ArrayList arrayList = new ArrayList();
arrayList.Add("ArrayList start");
IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(strFileName);
foreach (var directory in directories)
foreach (var tag in directory.Tags)
System.Diagnostics.Debug.WriteLine(string.Format("Directory " + $"{directory.Name} - {tag.Name} = {tag.Description}"));
count++;
ViewBag.listFromArray = arrayList;
return View(await db.ReadExifs.ToListAsync());
}

OpenCV Error: Assertion failed (scn == 3 || scn == 4) when calling Core.inRange

I am having an assertion error when using the Core.inRange function, actually any Core. function. I have followed all solutions in the answers from similar questions. Other solutions have been to check the number of channels, check if the image is empty and verify installation. I am using Android Studio 2.2 on Mac. Phones tested were ZTE Speed KitKat and Moto g3 Marshmallow.
My goal is to get the red and blue from an image -> determine if a Red light is On or a Blue one is on. The code gets the image from a Vuforia Frame, converts it to a bitmap and then try to use OpenCV to manipulate the image. This was working on previous code before we had to implement Vuforia as part of the core.
This is the main section of the code, the Imgproc.cvtColor function works fine, its the very last one Core.inRange
Mat mat1 = new Mat(640,480, CvType.CV_8UC4);
Mat mat2 = new Mat(640,480, CvType.CV_8UC4);
Mat mat3 = new Mat(640,480, CvType.CV_8UC4);
.......
Log.d("OPENCV","Height " + rgb.getHeight() + " Width " + rgb.getWidth());
Bitmap bm = Bitmap.createBitmap(rgb.getWidth(), rgb.getHeight(), Bitmap.Config.RGB_565);
bm.copyPixelsFromBuffer(rgb.getPixels());
//Mat tmp = OCVUtils.bitmapToMat(bm, CvType.CV_8UC4);
Mat tmp = new Mat(rgb.getWidth(), rgb.getHeight(), CvType.CV_8UC4);
Utils.bitmapToMat(bm, tmp);
SaveImage(tmp, "-raw");
fileLogger.writeEvent("process()","Saved original file ");
Log.d("OPENCV","CV_8UC4 Height " + tmp.height() + " Width " + tmp.width());
Log.d("OPENCV","Channels " + tmp.channels());
tmp.convertTo(mat1, CvType.CV_8UC4);
Size size = new Size(640,480);//the dst image size,e.g.100x100
resize(mat1,mat1,size);//resize image
SaveImage(mat1, "-convertcv_8uc4");
Log.d("OPENCV","CV_8UC4 Height " + mat1.height() + " Width " + mat1.width());
fileLogger.writeEvent("process()","converted to cv_8uc4");
Log.d("OPENCV","Channels " + mat1.channels());
Imgproc.cvtColor(mat1, mat2, Imgproc.COLOR_RGB2HSV_FULL);
SaveImage(mat2, "-COLOR_RGB2HSV_FULL");
Log.d("OPENCV","COLOR_RGB2HSV Height " + mat2.height() + " Width " + mat2.width());
Log.d("OPENCV","Channels " + mat2.channels());
//Core.inRange(mat2, RED_LOWER_BOUNDS_HSV, RED_UPPER_BOUNDS_HSV, mat3);
Log.d("OPENCV","mat2 Channels " + mat2.channels() + " empty " + mat2.empty());
Log.d("OPENCV","mat3 Channels " + mat3.channels() + " empty " + mat3.empty());
Core.inRange(mat2, new Scalar(0,100,150), new Scalar(22,255,255), mat3);
fileLogger.writeEvent("process()","Set Red window Limits: ");
SaveImage(mat3, "-red limits");
These are the 2 errors I get when the command runs
E/cv::error(): OpenCV Error: Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int), file /home/maksim/workspace/android-pack/opencv/modules/imgproc/src/color.cpp, line 7349
E/org.opencv.imgproc: imgproc::cvtColor_10() caught cv::Exception: /home/maksim/workspace/android-pack/opencv/modules/imgproc/src/color.cpp:7349: error: (-215) scn == 3 || scn == 4 in function void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int)
3 images are saved in the pictures directory as expected.
My logging produces the following
D/OPENCV: mat2 Channels 3 empty false
D/OPENCV: mat3 Channels 4 empty false
I have tried two different phones, tried adjusting the resolution down. I have reinstalled the OpenCV module in case it was not installed correctly. I have made the images all 3 channels, all 4 channels.
So after a week of debugging it was the most stupidest of mistakes!
Within the SaveImage function
Imgproc.cvtColor(mat, mIntermediateMat, Imgproc.COLOR_RGBA2BGR, 3);
This was what was causing the issue.
After the Core.inRange was the SaveImage function. Core.inRange dropped the channels to 1 - the fileLogger did not flush the last log, If I had used Log instead I probably would have picked it quicker.
public void SaveImage (Mat mat, String info) {
Mat mIntermediateMat = new Mat();
Imgproc.cvtColor(mat, mIntermediateMat, Imgproc.COLOR_RGBA2BGR, 3); <--Here bad
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String filename = "ian" + info + ".png";
File file = new File(path, filename);
Boolean bool = null;
filename = file.toString();
bool = Imgcodecs.imwrite(filename, mIntermediateMat);
if (bool == true)
Log.d("filesave", "SUCCESS writing image to external storage");
else
Log.d("filesave", "Fail writing image to external storage");
}

How do I append an int value into a string array in Swift?

I'm learning Swift now (with basic programming know-how), and I'm making a String array containing a deck of 52 cards via a for loop, but I'm not sure how to append a value with an int and string values.
I know using \(int) converts an int to a string, but it doesn't seem to work when appending to an array. My code, including the error messages are below:
var suits = ["Spades", "Hearts", "Clubs", "Diamonds"]
var deck:[String] = []
for s in suits
{
deck.append("Ace of " + s)
deck.append("King of " + s)
deck.append("Queen of " + s)
deck.append("Jack of " + s)
for (var i = 2; i < 11; ++i)
{
deck.append(\(i) + " of " + s)
//error message: "Expected ',' separator"
//error message: "Invalid character in source file"
}
}
You need to have your (i) in quotes in order for it to be converted to a String.
deck.append("\(i)" + " of " + s)
You could also do this:
var value = String(i)
deck.append(value + " of " + s)

Aggregating neighbouring pixels Python / GDAL and Numpy without interpolation

Consider we have an image of 2000 x 2000 pixels and the pixel size is 10 x 10 meters. The pixel values are also float numbers ranging from 0.00 - 10.00. This is image A.
I would like to resize image A to a quarter of its dimensions (i.e. 1000 x 1000 pixels) with a pixel size 20 x 20 meters (image B) by spatially aggregating four neighbouring pixels in non-overlapping blocks, starting from the top-left corner of the image, while the value for each pixel in image B will be a result of their arithmetic average.
I have written the following code using several sources from stackoverflow; however for some reason that I do not understand the resulting image (image B) is not always written properly and it is not readable by any of the software that I want to process it further (i.e. ArcGIS, ENVI, ERDAS etc).
I would appreciate any help
Best regards
Dimitris
import time
import glob
import os
import gdal
import osr
import numpy as np
start_time_script = time.clock()
path_ras='C:/rasters/'
for rasterfile in glob.glob(os.path.join(path_ras,'*.tif')):
rasterfile_name=str(rasterfile[rasterfile.find('IMG'):rasterfile.find('.tif')])
print 'Processing:'+ ' ' + str(rasterfile_name)
ds = gdal.Open(rasterfile,gdal.GA_ReadOnly)
ds_xform = ds.GetGeoTransform()
print ds_xform
ds_driver = gdal.GetDriverByName('Gtiff')
srs = osr.SpatialReference()
srs.ImportFromEPSG(26716)
ds_array = ds.ReadAsArray()
sz = ds_array.itemsize
print 'This is the size of the neighbourhood:' + ' ' + str(sz)
h,w = ds_array.shape
print 'This is the size of the Array:' + ' ' + str(h) + ' ' + str(w)
bh, bw = 2,2
shape = (h/bh, w/bw, bh, bw)
print 'This is the new shape of the Array:' + ' ' + str(shape)
strides = sz*np.array([w*bh,bw,w,1])
blocks = np.lib.stride_tricks.as_strided(ds_array,shape=shape,strides=strides)
resized_array = ds_driver.Create(rasterfile_name + '_resized_to_52m.tif',shape[1],shape[0],1,gdal.GDT_Float32)
resized_array.SetGeoTransform((ds_xform[0],ds_xform[1]*2,ds_xform[2],ds_xform[3],ds_xform[4],ds_xform[5]*2))
resized_array.SetProjection(srs.ExportToWkt())
band = resized_array.GetRasterBand(1)
zero_array = np.zeros([shape[0],shape[1]],dtype=np.float32)
print 'I start calculations using neighbourhood'
start_time_blocks = time.clock()
for i in xrange(len(blocks)):
for j in xrange(len(blocks[i])):
zero_array[i][j] = np.mean(blocks[i][j])
print 'I finished calculations and I am going to write the new array'
band.WriteArray(zero_array)
end_time_blocks = time.clock() - start_time_blocks
print 'Image Processed for:' + ' ' + str(end_time_blocks) + 'seconds' + '\n'
end_time = time.clock() - start_time_script
print 'Program ran for: ' + str(end_time) + 'seconds'
import time
import glob
import os
import gdal
import osr
import numpy as np
start_time_script = time.clock()
path_ras='C:/rasters/'
for rasterfile in glob.glob(os.path.join(path_ras,'*.tif')):
rasterfile_name=str(rasterfile[rasterfile.find('IMG'):rasterfile.find('.tif')])
print 'Processing:'+ ' ' + str(rasterfile_name)
ds = gdal.Open(rasterfile,gdal.GA_ReadOnly)
ds_xform = ds.GetGeoTransform()
print ds_xform
ds_driver = gdal.GetDriverByName('Gtiff')
srs = osr.SpatialReference()
srs.ImportFromEPSG(26716)
ds_array = ds.ReadAsArray()
sz = ds_array.itemsize
print 'This is the size of the neighbourhood:' + ' ' + str(sz)
h,w = ds_array.shape
print 'This is the size of the Array:' + ' ' + str(h) + ' ' + str(w)
bh, bw = 2,2
shape = (h/bh, w/bw, bh, bw)
print 'This is the new shape of the Array:' + ' ' + str(shape)
strides = sz*np.array([w*bh,bw,w,1])
blocks = np.lib.stride_tricks.as_strided(ds_array,shape=shape,strides=strides)
resized_array = ds_driver.Create(rasterfile_name + '_resized_to_52m.tif',shape[1],shape[0],1,gdal.GDT_Float32)
resized_array.SetGeoTransform((ds_xform[0],ds_xform[1]*2,ds_xform[2],ds_xform[3],ds_xform[4],ds_xform[5]*2))
resized_array.SetProjection(srs.ExportToWkt())
band = resized_array.GetRasterBand(1)
zero_array = np.zeros([shape[0],shape[1]],dtype=np.float32)
print 'I start calculations using neighbourhood'
start_time_blocks = time.clock()
for i in xrange(len(blocks)):
for j in xrange(len(blocks[i])):
zero_array[i][j] = np.mean(blocks[i][j])
print 'I finished calculations and I am going to write the new array'
band.WriteArray(zero_array)
end_time_blocks = time.clock() - start_time_blocks
print 'Image Processed for:' + ' ' + str(end_time_blocks) + 'seconds' + '\n'
end_time = time.clock() - start_time_script
print 'Program ran for: ' + str(end_time) + 'seconds'

Resources