Different Results From Magick++ and MagickNet

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
rondo
Posts: 8
Joined: 2018-11-15T13:47:59-07:00
Authentication code: 1152

Different Results From Magick++ and MagickNet

Post by rondo » 2018-11-26T09:28:16-07:00

I have created a program in MagickNet that calculates the number of pixels used on each CMYK channel. I have rewritten this program in Magick++, but I seem to get different results when I test it out on the same image. Is the channel separation different for Magick++ and MagickNet?

Code: Select all

//MagickNet
int[] cymkNumPixels = {0, 0, 0, 0};

MagickImage _canvas = new MagickImage("pathToImage");
_canvas.ColorSpace = ColorSpace.CMYK;

MagickImageCollection _channels = new MagickImageCollection();
_channels.AddRange(_canvas.Separate(ImageMagick.Channels.CMYK));
	
for (int i = 0; i < _channels.Count; i++)
{
	IPixelCollection pixCollection = _channels[i].GetPixels();
	
	for (int y = 0; y < _canvas.Height; y++)
		for (int x = 0; x < _canvas.Width; x++)
			if (pixCollection.GetPixel(x, y).ToColor().R != 0)
				cmykNumPixels[channelCount]++;
}


//Magick++
int cymkNumPixels[4] = {0, 0, 0, 0};

Image _canvas = new Image("pathToImage");
_canvas.colorSpace(CMYKColorspace);

for (size_t channel = 0; channel < _canvas.channels(); channel++)
{	
	Image temp = _canvas;

	if (channel == 0) { temp.channel(CyanChannel); }
	else if(channel == 1) { temp.channel(MagentaChannel); }
	else if (channel == 2) { temp.channel(YellowChannel); }
	else if (channel == 3) { temp.channel(BlackChannel); }

	for (size_t y = 0; y < temp.columns(); y++)
		for (size_t x = 0; x < temp.rows(); x++)
			if (temp.pixelColor(x, y).quantumRed() != 0)
				cmykNumPixels[channel]++;
}

User avatar
dlemstra
Posts: 1563
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Different Results From Magick++ and MagickNet

Post by dlemstra » 2018-11-26T10:55:28-07:00

You swapped columns and rows in the c++ code.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

rondo
Posts: 8
Joined: 2018-11-15T13:47:59-07:00
Authentication code: 1152

Re: Different Results From Magick++ and MagickNet

Post by rondo » 2018-11-26T11:05:53-07:00

Ahh, good catch. Thank you!

Post Reply