In a C# project, I ve got error using the AddImageFilter which is provided in the SimpleITK. Is there a common mistake that happens when trying to add two images with this filter? For example, maybe there is a rule the images should be both double or int.
The error I get is:
Image2 for AddImageFilter doesnt match type or dimension!
In a certain sense, your supposition is right. I couldn't been able to find the exact error you've got, but I found this sitkAddImageFilter implementation on GitHub. If you look at the AddImageFilter::Execute() function, at line 33, you'll find this exception been throwed:
std::cerr << "Both image for add filter don't match type or dimension!" << std::endl;
that seems related to yours (maybe the slight difference is just related to a different version of ITK). And that exception is throwed whenever this is verified:
if ( type != image2->GetDataType() || dimension != image2->GetDimension() )
So, a condition for the AddImageFilter is that both dimensions must be the same, and the metadata associated with the images must agree. This makes sense, because matrices addition is doable only when their dimensions match (and, of course, when they contain the same kind of informations).
If you are trying to add two different kinds of images (as an example: a DICOM with a TIFF), I suggest to convert at least one of them, in a way to have both of them in the same "metadata space".
The error message is a little vague and should be improved.
Many filters which take more than one image as input expect the following that pixel type, dimension, size, spacing and orientation to be same. The error message you got indicates that the pixel type or the size do not match. Likely emanating from the code generated from is line:
https://github.com/SimpleITK/SimpleITK/blob/master/TemplateComponents/ExecuteNoParameters.cxx.in#L8
I'd recommend printing your two images as strings to examine the meta-data to determine the difference.
Related
I am trying to read the data stored in an ICMT tag on a WAV file generated by a noise monitoring device.
The RIFF parsing code all seems to work fine, except for the fact that the ICMT tag seems to have data after the declared size. As luck would have it, it's the timestamp, which is the one absolutely critical piece of info for my application.
SYN is hex 16, which gives a size of 22, which is up to and including the NUL before the timestamp. The monitor documentation is no help; it says that the tag includes the time, but their example also has the same issue.
It is the last tag in the enclosing list, and the size of the list does include it - does that mean it doesn't need a chunk ID? I'm struggling to find decent RIFF docs, but I can't find anything that suggests that's the case; also I can't see how it'd be possible to determine that it was the last chunk and so know to read it with no chunk ID.
Alternatively, the ICMT comment chunk is the last thing in the file - is that a special case? Can I just get the time by reading everything from the end of the declared length ICMT to the end of the file and assume that will always work?
The current parser behaviour is that it's being read after the channel / dB information as a chunk ID + size, and then complaining that there was not enough data left in the file to fulfil the request.
No, it would still need its own ID. No, being the last thing in the file is no special case either. What you're showing here is malformed.
Your current parser errors correctly, as the next thing to be expected again is a 4 byte ID followed by 4 bytes for the length. The potential ID _10: is unknown and would be skipped, but interpreting 51:4 as DWORD for the length of course asks for trouble.
The device is the culprit. Do you have other INFO fields which use NULL bytes? If not then I assume the device is naive enough to consider a NULL the end of a string, despite producing himself strings with multiple NULLs.
Since I encountered countless files not sticking to standards I can only say your parser is too naive as well: it knows how long the encapsulating list is and thus could easily detect field lengths that would not fit anymore. And could ignore garbage like that. Or, in your case, offer the very specific option "add to last field".
My question is pretty similar to this one and I'm afraid the answer is the same... I want to save all the shapes/images on a slide as a single png (or jpeg). Programmatically, I get as far as
slide.Shapes.SelectAll();
but don't see a way to save as image. Is this possible? If not, any other suggestions, hopfully w/ examples? (not VBA - I need to automate the whole conversion)
There was a reference to OpenXML in the other post, but I'm not even sure how to pull that in.
I don't know how you'd do this in C# but I'd guess that you'd make use of the same methods as you would with VBA, where you can do:
Activewindow.Selection.ShapeRange.Export( "c:\temp\delete-me.jpg",ppShapeFormatJPG)
ppShapeFormatJPG is a PowerPoint constant, a VBA Long = 1; IIRC that'd be an Integer in C#.
The method also can take two more optional parameters, scalewidth and scaleheight, which govern the width and height of the exported image in undocumented ways. By default, no parms supplied, I get exports at 72 dpi. Larger numbers result in higher pixel count exports but distorted proportions. I'm sure there's some strange logic to it, but it escapes me; all hints welcome!
There's a third optional parm, ExportMode. In my tests, it makes no difference whether you supply it or not, and if you do, which of the available values you choose.
Is it possible to compare two images with a mask for area's that do not need to be compared.
I managed to get it working with a basic file comparison
[UseReporter(typeof(BeyondCompareReporter))]
public void ThenThePageShouldMatchTheApprovedVersion()
{
SaveScreenshot("page1");
Approvals.VerifyFile(#"C:\page1.png");
}
But i would like to create a mask of the area's i expect to change. Is this possible with ApprovalTests or will i need to modify the screenshot and manually apply the mask before comparing with the approved file. Or is it possible to write your own validators?
It's not possible to mask the area so the comparer will not compare them.
However, it is very easy to actually mask the area (ie, place a black square over the area before you call Verify)
Alternatively, you can usually mock out the variable that is changing.
Details on Comparer:
ApprovalsFileComparer is a very stupid comparer. It knows nothing about file formats and has no idea of what an image is. It simply compares byte to byte. This simplicity allows it to work everywhere, but removes the ability to be smart about stuff. This is usually not an issue as the reporters are very very smart. Able to render and compare and do subtractive diffs and the like.
Happy Testing!
I've Google'd and read quite a bit on QR codes and the maximum data that can be used based on the various settings, all of it being in tabular format. I can't seem to find anything giving a formula or a proper explanation of how these values are calculated.
What I would like to do is this:
Present the user with a form, allowing them to choose Format, EC & Version.
Then they can type in some data and generate a QR code.
Done deal. That part is easy.
The addition I would like to include is a "remaining character count" so that they (the user) can see how much more data they can type in, as well as what effect the properties have on the storage capacity of the QR code.
Does anyone know where I can find the formula(s)? Or do I need to purchase ISO 18004:2006?
A formula to calculate the amount of data you could put in a QRcode would be quite complex to make, not mentioning it would need some approximations for the calculation to be possible. The formula would have to calculate the amount of modules dedicated to the data in your QRCode based on its version, and then calculate how many codewords (which are sets of 8 modules) will be used for the error correction.
To calculate the amount of modules that will be used for the data, you need to know how many modules will be used for the function patterns. While this is not a problem for the three finder patterns, the timing or the version/format information, there will be a problem with the alignment patterns as their number is dependent on the QRCode's version, meaning you anyway would have to use a table at that point.
For the second part, I have to say I don't know how to calculate the number of error correcting codewords based on the correction capacity. For some reason, there are more error correcting codewords used that there should to match the error correction capacity, as for example a 6-H QRCode can correct up to 32.6% of the data, instead of the 30% set by the H correction level.
In any case, as you can see a formula would be quite complex to implement. Using a table like already suggested is probably the best thing you could do.
I wrote the original AIM specification for QR Code back in the '90s for Denso Corporation, and was also project editor for both editions of the ISO/IEC 18004 standard. It was felt to be much easier for people producing code printing software to use a look-up table rather than calculate capacities from a formula - no easy job as there are several independent variables that have to be taken into account iteratively when parsing the text to be encoded to minimise its length in bits, in order to achieve the smallest symbol. The most crucial factor is the mix of characters in the data, the sequence and lengths of sub-strings of numeric, alphanumeric, Kanji data, with the overhead needed to signal each change of character set, then the required level of error correction. I did produce a guidance section for this which is contained in the ISO standard.
The storage is calculated by the QR mode and the version/type that you are using. More specifically the calculation is based on how 'compressible' the characters are and what algorithm that the qr generator is allowed to use on the content present.
More information can be found http://en.wikipedia.org/wiki/QR_code#Storage
While extracting color from PDF using iTextSharp I get this error :
int r = renderInfo.GetColorNonStroke().R;
int g = renderInfo.GetColorNonStroke().G;
int b = renderInfo.GetColorNonStroke().B;
Error message :
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception details:
System.NullReferenceException: Object reference not set to an instance of an object.
As GetColorNonStroke is not a method of the original iTextSharp TextRenderInfo, I assume you are using a version patched according to #ChrisHaas' blog entry Getting color information from iTextSharp’s TextRenderInfo and ITextExtractionStrategy.
The members colorStroke and colorNonStroke of GraphicsState (the values of which are returned by the TextRenderInfo methods GetColorStroke and GetColorNonStroke respectively) are initialized with null.
Thus, as long as there was no explicit command before to set the stroking or non-stroking color, the respective TextRenderInfo method GetColorStroke or GetColorNonStroke will return null.
Therefore, whenever you use renderInfo.GetColorNonStroke(), check it for null before accessing its members. If the color is null, assume the default.
Furthermore, #ChrisHaas' color extension of iTextSharp's parsing capabilities uses different kinds of color objects: GrayColor, BaseColor, and CMYKColor. Depending on your requirements you might want to test the type of color returned to you.
In case of special colors, Chris Haas even writes:
SCN and scn themselves are catchalls for everything else that’s not RGB, CMYK or Grey. Before hitting one of those two you should actually first find a CS operator whose first and only operand is the actual color space to use. There’s a bunch of options for this including DeviceRGB, DeviceCMYK, Pattern, Lab, DeviceN, etc. You can find these in table 74 of the 2008 PDF spec section 8.6.8 (page 171). My code is actually not completely correct and I shouldn’t be pushing CS and cs to the SetStrokingGeneral method but instead should do some further processing. Unfortunately none of the samples PDFs that I had at the time had this set so I couldn’t test for it. Hopefully this helps you out!