Page 1 of 1

Different Results From Magick++ and MagickNet

Posted: 2018-11-26T09:28:16-07:00
by rondo
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]++;
}

Re: Different Results From Magick++ and MagickNet

Posted: 2018-11-26T10:55:28-07:00
by dlemstra
You swapped columns and rows in the c++ code.

Re: Different Results From Magick++ and MagickNet

Posted: 2018-11-26T11:05:53-07:00
by rondo
Ahh, good catch. Thank you!