Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
SebastianR  
#1 Posted : Friday, May 12, 2017 4:53:26 AM(UTC)
SebastianR

Rank: Advanced Member

Groups: Member
Joined: 5/10/2017(UTC)
Posts: 33

Thanks: 10 times
Was thanked: 1 time(s) in 1 post(s)
Hello,

I want to resize and unsharp a large image
Code:

var targetSize = new Size(200, 100);
using (var resize = new Resize(targetSize, ResizeInterpolationMode.Lanczos3, ResizeMode.Fit))
using (var unsharp = new UnsharpMask(0.35f, 1f, 0f))

and then imprint on a white background
Code:
using (var bgGen = new ImageGenerator(targetSize, reader.PixelFormat, backgroundColor))

but the combiner takes only a topimage as argument (the background ist the image in the pipeline). Since both images are results of a pipeline how do I have to construct that pipeline (preferably without using two separate pipelines)?

Fedor  
#2 Posted : Friday, May 12, 2017 5:43:01 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
This code should give you an idea how to implement it:

Code:
var targetSize = new Size(200, 100);
var backgroundColor = RgbColor.Green;

using (var reader = ImageReader.Create("../../../in.png"))
using (var resize = new Resize(targetSize, ResizeInterpolationMode.Lanczos3, ResizeMode.Fit))
using (var unsharp = new UnsharpMask(0.35f, 1f, 0f))
using (var bgGen = new ImageGenerator(targetSize, reader.PixelFormat, backgroundColor))
using (var combiner = new Combiner())
using (var writer = ImageWriter.Create("../../../out.png"))
{
	combiner.Mode = CombineMode.Alpha;
	combiner.TopImage = (reader + resize + unsharp);

	(bgGen + combiner + writer).Run();
}


Please note, you can manually construct a pipeline instead of using the plus operator:

Code:
combiner.TopImage = (reader + resize + unsharp);

-->
Code:
var topImage = new Pipeline();
topImage.Add(reader);
topImage.Add(resize);
topImage.Add(unsharp);
				
combiner.TopImage = topImage;


You can find more information here:

https://www.graphicsmill.com/doc...nes.htm#overlayingImages
Best regards,
Fedor Skvortsov
thanks 1 user thanked Fedor for this useful post.
SebastianR on 5/12/2017(UTC)
SebastianR  
#3 Posted : Friday, May 12, 2017 6:01:52 AM(UTC)
SebastianR

Rank: Advanced Member

Groups: Member
Joined: 5/10/2017(UTC)
Posts: 33

Thanks: 10 times
Was thanked: 1 time(s) in 1 post(s)
Brick wall Thank you. I missed the forest for the trees.
SebastianR  
#4 Posted : Monday, May 15, 2017 1:13:22 AM(UTC)
SebastianR

Rank: Advanced Member

Groups: Member
Joined: 5/10/2017(UTC)
Posts: 33

Thanks: 10 times
Was thanked: 1 time(s) in 1 post(s)
Extension of the original question.

I want to place the topImage in the middle of the generated background.

Code:

var targetSize = new Size(200, 100);
var backgroundColor = RgbColor.Green;

using (var reader = ImageReader.Create("../../../in.png"))
using (var resize = new Resize(targetSize, ResizeInterpolationMode.Lanczos3, ResizeMode.Fit))
using (var unsharp = new UnsharpMask(0.35f, 1f, 0f))
using (var bgGen = new ImageGenerator(targetSize, reader.PixelFormat, backgroundColor))
using (var combiner = new Combiner())
using (var writer = ImageWriter.Create("../../../out.png"))
{
	combiner.Mode = CombineMode.Alpha;
	var topImage = (reader + resize + unsharp);
	combiner.TopImage = topImage;

	// this doesn't work
	combiner.X = (int)Math.Round((double)(targetSize.Width - topImage.Width) / 2);
	combiner.Y = (int)Math.Round((double)(targetSize.Height - topImage.Height) / 2);

	(bgGen + combiner + writer).Run();
}


Problem is the new Width and Height of the new topImage are not available. Are they? And, if so, where do I find them?

So far I'm back to a separate pipeline.
Fedor  
#5 Posted : Monday, May 15, 2017 8:44:33 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
You should specify a target image size explicitly instead of using ResizeMode.Fit:

Code:
var targetSize = new Size(200, 100);
var backgroundColor = RgbColor.Green;

using (var reader = ImageReader.Create("../../../in.png"))
using (var resize = new Resize())
using (var unsharp = new UnsharpMask(0.35f, 1f, 0f))
using (var bgGen = new ImageGenerator(targetSize, reader.PixelFormat, backgroundColor))
using (var combiner = new Combiner())
using (var writer = ImageWriter.Create("../../../out.png"))
{
	var actualTargetSize = Resize.CalculateDimensions(new Size(reader.Width, reader.Height),
		targetSize, ResizeMode.Fit);

	resize.Width = actualTargetSize.Width;
	resize.Height = actualTargetSize.Height;
	resize.ResizeMode = ResizeMode.Resize;

	combiner.Mode = CombineMode.Alpha;
	var topImage = (reader + resize + unsharp);
	combiner.TopImage = topImage;

	combiner.X = (int)Math.Round((double)(targetSize.Width - actualTargetSize.Width) / 2);
	combiner.Y = (int)Math.Round((double)(targetSize.Height - actualTargetSize.Height) / 2);

	(bgGen + combiner + writer).Run();
}
Best regards,
Fedor Skvortsov
thanks 1 user thanked Fedor for this useful post.
SebastianR on 5/17/2017(UTC)
SebastianR  
#6 Posted : Wednesday, May 17, 2017 11:38:37 PM(UTC)
SebastianR

Rank: Advanced Member

Groups: Member
Joined: 5/10/2017(UTC)
Posts: 33

Thanks: 10 times
Was thanked: 1 time(s) in 1 post(s)
That did it, thank you.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.