public ImageKey[] BuildImageKeysToDown() { List <ImageKey> list = new List <ImageKey>(); int lastEpisodeNo = webtoonInfo.GetLastEpisodeNo(); for (int episodeNo = 1; episodeNo <= lastEpisodeNo; episodeNo++) { if (!webtoonInfo.Episodes.ContainsKey(episodeNo)) { continue; } EpisodeInfo episodeInfo = webtoonInfo.Episodes[episodeNo]; string[] imageUrls = episodeInfo.EpisodeImageUrls; for (int imageIndex = 0; imageIndex < imageUrls.Length; imageIndex++) { ImageKey imageKey = new ImageKey(webtoonInfo.WebtoonTitleId, episodeNo, imageIndex); if (File.Exists(fileNameBuilder.BuildImageFileFullPath(imageKey))) { continue; } list.Add(imageKey); } } return(list.ToArray()); }
static BitmapSource TryGetImage(ImageSourceInfo img, Size size) { if (img is null) { return(null); } var key = new ImageKey(img.Uri, size); BitmapSource image; if (imageCache.TryGetValue(key, out var bmp)) { return(bmp); } image = TryLoadImage(img, size); if (image is null) { return(null); } imageCache[key] = image; return(image); }
public (int downloadedImageCount, long downloadedImagesSize) GetDownloadedImagesInformation() { WebtoonKey webtoonKey = new WebtoonKey(webtoonInfo.WebtoonTitleId); int count = 0; long size = 0; int lastEpisode = webtoonInfo.GetLastEpisodeNo(); for (int episodeNo = 1; episodeNo <= lastEpisode; episodeNo++) { if (!webtoonInfo.Episodes.ContainsKey(episodeNo)) { continue; } EpisodeInfo episodeInfo = webtoonInfo.Episodes[episodeNo]; string[] imageUrls = episodeInfo.EpisodeImageUrls; for (int imageIndex = 0; imageIndex < imageUrls.Length; imageIndex++) { ImageKey imageKey = new ImageKey(webtoonInfo.WebtoonTitleId, episodeNo, imageIndex); if (File.Exists(fileNameBuilder.BuildImageFileFullPath(imageKey))) { count++; size += new FileInfo(fileNameBuilder.BuildImageFileFullPath(imageKey)).Length; } } } return(count, size); }
protected static IPresentationImage GetImage(ImageKey key) { string filename = string.Format(_testImagePathFormat, key.ToString().ToLower()); try { LocalSopDataSource dataSource = new LocalSopDataSource(filename); ImageSop imageSop = new ImageSop(dataSource); IPresentationImage theOne = null; foreach (IPresentationImage image in PresentationImageFactory.Create(imageSop)) { if (theOne == null) { theOne = image; continue; } image.Dispose(); } imageSop.Dispose(); return(theOne); } catch (Exception ex) { throw new FileNotFoundException("Unable to load requested test image. Please check that the assembly has been built.", filename, ex); } }
BitmapSource TryGetImage(string uriString, InternalImageOptions options) { if (uriString == null) { return(null); } var key = new ImageKey(uriString, options); WeakReference weakImage; BitmapSource image; if (imageCache.TryGetValue(key, out weakImage)) { image = weakImage.Target as BitmapSource; if (image != null) { return(image); } } image = TryLoadImage(uriString, options.PhysicalSize); if (image == null) { return(null); } if (options.BackgroundColor != null) { image = ThemedImageCreator.CreateThemedBitmapSource(image, options.BackgroundColor.Value, isHighContrast); } imageCache[key] = new WeakReference(image); return(image); }
private void addImageDescription(Direction direction, ImageKey key) { imageDescriptions.Add(new ImageDescription { Direction = direction, Key = key }); }
/// <summary> /// imageKey가 지정하는 이미지의 전체 폴더 경로 문자열을 반환합니다. /// </summary> /// <param name="imageKey"></param> /// <returns></returns> public string BuildImageFileFullDirectory(ImageKey imageKey) { string directory = config.DefaultDownloadDirectory + "\\" + BuildWebtoonDirectoryName(imageKey) + "\\" + BuildEpisodeDirectoryName(imageKey); return(directory); }
/// <summary> /// imageKey가 지정하는 이미지의 전체 경로 문자열을 반환합니다. /// </summary> /// <param name="imageKey"></param> /// <returns></returns> private static string BuildImageFileFullDirectory(WebtoonInfo webtoonInfo, ImageKey imageKey) { string directory = config.DefaultDownloadDirectory + "\\" + BuildWebtoonDirectoryName(webtoonInfo, imageKey) + "\\" + BuildEpisodeDirectoryName(webtoonInfo, imageKey); return(directory); }
/// <summary> /// imageKey가 지정하는 이미지의 전체 파일 경로문자열을 반환합니다. /// </summary> /// <param name="imageKey"></param> /// <returns></returns> public string BuildImageFileFullPath(ImageKey imageKey) { string path = config.DefaultDownloadDirectory + "\\" + BuildWebtoonDirectoryName(imageKey) + "\\" + BuildEpisodeDirectoryName(imageKey) + "\\" + BuildImageFileName(imageKey); return(path); }
private void addLocation(int i, ImageKey imageKey) { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri(i + ".PNG", UriKind.Relative); bitmapImage.EndInit(); imageLocations.Add(new ImageLocation() { Key = imageKey, Image = bitmapImage });; }
/// <summary> /// Tests the length measurement for a specific shape on a specific image. /// </summary> protected void TestRoiLengthMeasurement(ImageKey key, T shapeData, double expectedLength, double toleranceLength, Units lengthUnits) { string description = string.Format("{0} on {1}", shapeData, key); using (IPresentationImage image = GetImage(key)) { // simulates ROIs that an end-user would create using graphics constructed by the tools Roi userRoi = CreateRoiFromGraphic((IOverlayGraphicsProvider)image, shapeData); PerformRoiLengthMeasurements(userRoi, expectedLength, toleranceLength, "user", description, lengthUnits); // simulates ROIs that a programmer might create using the SDK directly, rather than via graphics Roi sdkRoi = CreateRoiFromImage(image, shapeData); PerformRoiLengthMeasurements(sdkRoi, expectedLength, toleranceLength, "SDK", description, lengthUnits); } }
/// <summary> /// Tests the area, mean and standard deviation calculations for a specific shape on a specific image. /// </summary> protected void TestRoiStatsCalculations(ImageKey key, T shapeData, double expectedPerimeter, double expectedArea, double expectedMean, double expectedSigma, Units areaPerimeterUnits) { string description = string.Format("{0} on {1}", shapeData, key); using (IPresentationImage image = GetImage(key)) { // simulates ROIs that an end-user would create using graphics constructed by the tools Roi userRoi = CreateRoiFromGraphic((IOverlayGraphicsProvider)image, shapeData); PerformRoiStatsCalculations(userRoi, expectedPerimeter, expectedArea, expectedMean, expectedSigma, "user", description, areaPerimeterUnits); // simulates ROIs that a programmer might create using the SDK directly, rather than via graphics Roi sdkRoi = CreateRoiFromImage(image, shapeData); PerformRoiStatsCalculations(sdkRoi, expectedPerimeter, expectedArea, expectedMean, expectedSigma, "SDK", description, areaPerimeterUnits); } }
/// <summary> /// imageKey가 지정하는 이미지의 파일명을 정의된 포맷 형식(<seealso cref="Config.ImageFileNameFormat"/>)에 따라 생성합니다. /// </summary> /// <param name="imageKey"></param> /// <returns></returns> private static string BuildImageFileName(WebtoonInfo webtoonInfo, ImageKey imageKey) { string titleId = imageKey.TitleId; int episodeNo = imageKey.EpisodeNo; int ImageIndex = imageKey.ImageIndex; string webtoonTitle = webtoonInfo.WebtoonTitle; string episoneTitle = webtoonInfo.Episodes[imageKey.EpisodeNo].EpisodeTitle; return(string.Format(config.ImageFileNameFormat, titleId, episodeNo, ImageIndex, ReplaceFileName(webtoonTitle), ReplaceFileName(episoneTitle), webtoonInfo.Episodes[imageKey.EpisodeNo].EpisodeDate)); }
protected void RunAngleTest(ImageKey key, float expectedAngle, string dumpFilename, params Angle[] shapes) { ProtractorAngleCalculator analyzer = new ProtractorAngleCalculator(); Trace.WriteLine(string.Format("Using {0} for test case {1}", key, dumpFilename), "UNIT_TESTS"); using (IPresentationImage image = GetImage(key)) { IImageSopProvider sopProvider = (IImageSopProvider)image; DicomAttribute attribute; if (sopProvider.Sop.DataSource.TryGetAttribute(DicomTags.PixelAspectRatio, out attribute)) { Trace.WriteLine("PixelAspectRatio (0028,0034) PRESENT", "UNIT_TESTS"); } if (!sopProvider.Frame.PixelSpacing.IsNull) { Trace.WriteLine("PixelSpacing (0028,0030) or equivalent PRESENT", "UNIT_TESTS"); } try { foreach (Angle shapeData in shapes) { Roi roi = CreateRoiFromGraphic((IOverlayGraphicsProvider)image, shapeData); var actualResult = analyzer.Analyze(roi, RoiAnalysisMode.Normal); float actualAngle = float.Parse(RegexAngleMeasurement.Match(actualResult.SerializedAsString()).Groups[1].Value, CultureInfo.InvariantCulture); Trace.WriteLine(String.Format("Actual: {0} degrees, Expected: {1} degrees", actualAngle, expectedAngle)); Assert.AreEqual(expectedAngle, actualAngle, 0.5f, "Testing Angle {0}", shapeData); // allow half degree tolerance } } finally { if (DumpMeasuredImages && !string.IsNullOrEmpty(dumpFilename)) { using (Bitmap bmp = image.DrawToBitmap(256, 256)) { bmp.Save(string.Format("{1}-{0}.bmp", key, dumpFilename), ImageFormat.Bmp); } } } } }
/// <summary> /// Añade un nodo /// </summary> private TreeNode AddNode(TreeNode trnParent, TreeNodeType intNode, ImageKey intImage, string strText, bool blnBold, Color clrColor, object objTag) { Bau.Controls.Tree.TreeNodeKey objKey = new Bau.Controls.Tree.TreeNodeKey((int) intNode, trvContacts.Nodes.Count + 1, objTag); // Añade el nodo return trvContacts.AddNode(trnParent, objKey, strText, false, (int) intImage, clrColor, blnBold); }
protected void SetImage(ImageKey imageKey, string image) { this.images[imageKey] = image; }
internal string GetImage(ImageKey key) { return(this.images[key]); }
public override int GetHashCode() { unchecked { return(((ImagePath != null ? ImagePath.GetHashCode() : 0) * 397) ^ (ImageKey != null ? ImageKey.GetHashCode() : 0)); } }
/// <summary> /// Tests the <see cref="Roi.Contains(System.Drawing.PointF)"/> method for a given shape. The image is used to provide a basis for the coordinate space. /// </summary> protected void TestRoiContains(ImageKey key, T shapeData, string name) { using (IPresentationImage image = GetImage(key)) { IImageSopProvider provider = (IImageSopProvider)image; using (Bitmap bmp = new Bitmap(provider.Frame.Columns, provider.Frame.Rows)) { using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp)) { g.Clear(Color.Black); // baseline ROI using GDI's GraphicsPath using (GraphicsPath graphicsPath = new GraphicsPath()) { AddShapeToGraphicsPath(graphicsPath, shapeData); g.FillPath(Brushes.Blue, graphicsPath); } } // simulates ROIs that an end-user would create using graphics constructed by the tools Roi userRoi = CreateRoiFromGraphic((IOverlayGraphicsProvider)image, shapeData); userRoi.PixelData.ForEachPixel(delegate(int i, int x, int y, int pixelIndex) { if (userRoi.Contains(x, y)) { bmp.SetPixel(x, y, ShiftColor(bmp.GetPixel(x, y), true, false, false)); } }); // simulates ROIs that a programmer might create using the SDK directly, rather than via graphics Roi sdkRoi = CreateRoiFromImage(image, shapeData); sdkRoi.PixelData.ForEachPixel(delegate(int i, int x, int y, int pixelIndex) { if (sdkRoi.Contains(x, y)) { bmp.SetPixel(x, y, ShiftColor(bmp.GetPixel(x, y), false, true, false)); } }); string filename = string.Format("{0}.{1}.containment.test.png", name, this.ShapeName).TrimStart('.'); bmp.Save(filename); Trace.WriteLine(string.Format("Pixel containment map has been dumped to {0}.", filename)); int totalCount = 0; int errorCount = 0; for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { Color c = bmp.GetPixel(x, y); if (c.R > 0 || c.G > 0 || c.B > 0) { totalCount++; if (c.R < 255 || c.G < 255 || c.B < 255) { errorCount++; } } } } if (errorCount > 0) { WriteLine("The pixel containment test results are not perfect. {0} differences were found out of {1} pixels.", errorCount, totalCount); WriteLine("The image should be mostly a white shape on a black background."); WriteLine("Any coloured areas indicate locations where Roi.Contains(...) did not return perfectly coincident results."); WriteLine("There will invariably be such areas along shape boundaries, but the shape should be white overall."); WriteLine("Red channel is painted by user mode ROI. Green channel is painted by SDK. Blue channel is painted by GDI+."); } Assert.AreEqual(0, errorCount, 0.01 * totalCount, "Automated pixel containment test failed. Please review the test output manually."); } } }
public RedisImageArray GetByteArrayData(ImageKey key) => GetByteArrayData(key.ToString());
public byte[] GetByteData(ImageKey key) => GetByteData(key.ToString());
/// <summary> /// Tests the area, mean and standard deviation calculations for a specific shape on a specific image. /// </summary> protected void TestRoiStatsCalculations(ImageKey key, T shapeData, double expectedPerimeter, double expectedArea, double expectedMean, double expectedSigma) { this.TestRoiStatsCalculations(key, shapeData, expectedPerimeter, expectedArea, expectedMean, expectedSigma, Units.Pixels); }
private void bottomEqual(Direction direction, ImageKey key) { Assert.AreEqual(direction, Handler.getBottomImage().Direction); Assert.AreEqual(key, Handler.getBottomImage().Key); }
private void leftEqual(Direction direction, ImageKey key) { Assert.AreEqual(direction, Handler.getLeftImage().Direction); Assert.AreEqual(key, Handler.getLeftImage().Key); }
public BitmapImage getImageByKey(ImageKey key) { return(imageLocations.Find(image => image.Key == key).Image); }
/// <summary> /// Tests the length measurement for a specific shape on a specific image. /// </summary> protected void TestRoiLengthMeasurement(ImageKey key, T shapeData, double expectedLength) { TestRoiLengthMeasurement(key, shapeData, expectedLength, 0.25, Units.Pixels); }