Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, December 14, 2010 9:48:17 AM(UTC)

RLenski  
RLenski

Groups: Registered
Posts: 12


What I am trying to do is determine information about a selected region of an image loaded into a LBitmapWindow. Basically I am trying to determine the percentage of colors within a selected region. The user clicks on an area in the LBitmapWindow and I popup a window and show the user the percentage of cyan, magenta, yellow and black within that region. I have just about everything working using the GetPixelColor() from the LBitmapWindow. I just now want to expand that using a region instead of a pixel. Below is what I am doing to try and get the region to calculate the color values that doesn't seem to be working:

POINT pt = point;
POINT bitmapPoint;
RECT rcDst;

m_LBitmapWnd.GetRects(NULL, NULL, &rcDst, NULL);

bitmapPoint.x = (pt.x - rcDst.left);
bitmapPoint.y = (pt.y - rcDst.top);

bitmapPoint.x = (long)(bitmapPoint.x * 100 / m_LBitmapWnd.GetZoomPercent());
bitmapPoint.y = (long)(bitmapPoint.y * 100 / m_LBitmapWnd.GetZoomPercent());

// Set the region Left Right Top Bottom
CRect rect(bitmapPoint.x - 25, bitmapPoint.y - 25, bitmapPoint.x + 25, bitmapPoint.y + 25);
LBitmapRgn Region(&m_LBitmapWnd);
Region.SetRgnRect(&rect);

STATISTICSINFO StatisticsInfo;
// Get the statistics info for Region?
L_INT nRet = m_LBitmapWnd.GetStatisticsInfo(&StatisticsInfo,CHANNEL_MASTER, 0, 255);

Any help would be appreciated on how to get the region from the LBitmapWindow to calculate the color percentages within that region. Also any examples on how to calculate the cmyk from the region (bit by bit?) would also be helpful. Thanks in advance.

Thanks,
Rich
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, December 15, 2010 5:32:36 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,328

Was thanked: 1 time(s) in 1 post(s)

Rich,
The GetStatisticsInfo function does not directly retrieve CMYK information.
You could produce CMYK data for a rectangular region in a different way as follows:
1. Use the LBitmapBase::CopyRect() function to create a new LBitmap that only contains the desired rectangle.
2. Use the LBitmap::ColorSeparate() function with the COLORSEP_CMYK flag to produce 4 plane bitmaps, one for each component.
3. Retrieve your data from the 4 plane bitmaps (C, M, Y and K).
If you still face problems with that, please tell me what you tried and what your equipments are exactly.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#3 Posted : Thursday, December 16, 2010 12:08:06 PM(UTC)

RLenski  
RLenski

Groups: Registered
Posts: 12


Maen,

Thanks again for all of your help. I think I have everything working properly except I am trying to find a function that I can use to calculate the pixels from the separated files. I have taken a slice of the 8bit image file from the LBitmapWindow, copied into a LBitmap and separated the files into CMYK LBitmap files. I now have the 4 separated files into 8bit LBitmap files. I just wanted to find out if there is a way for me to get the number of pixels in that separated file that are the cyan, magenta, or yellow colors? For example in that separated cyan LBitmap image I have how many are cyan bits? I have tried with the GetStatisticsInfo(), but not sure if that is giving me the data I want. Below is a small example of what I have tried. Thanks again.

Thanks,
Rich

LBitmap ColorPlanes[4]; /* Array of bitmap handles */
L_INT nRet = m_MyBitmap.ColorSeparate(ColorPlanes, sizeof(BITMAPHANDLE), COLORSEP_CMYK);
if( nRet == SUCCESS )
{
STATISTICSINFO CyanStats, MagStats, YellowStats, BlackStats, AllStats;
nRet = ColorPlanes[0].GetStatisticsInfo(&CyanStats,CHANNEL_MASTER, 0, 255);
nRet = ColorPlanes[1].GetStatisticsInfo(&MagStats,CHANNEL_MASTER, 0, 255);
nRet = ColorPlanes[2].GetStatisticsInfo(&YellowStats,CHANNEL_MASTER, 0, 255);
nRet = ColorPlanes[3].GetStatisticsInfo(&BlackStats,CHANNEL_MASTER, 0, 255);

CString sCyan;
sCyan.Format("Dev:%.2f, Mean:%.2f, Med:%i, Max:%i, Min:%i",
CyanStats.dStdDev, CyanStats.dMean, CyanStats.nMedian, CyanStats.nMax, CyanStats.nMin );
}
 
#4 Posted : Sunday, December 19, 2010 5:05:45 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,328

Was thanked: 1 time(s) in 1 post(s)

The solution depends on what exactly you mean by number of pixels that of a certain color.
The pixels of the original image (and the corresponding values of the 4 plane pixels) can have any value. For example, a pure black pixel might have C=0, M=0, Y=0 and K=255.

However, some other color might have C=50, M=52, Y=53 and K=55. Would this pixel be counted as C, M, Y or K? What is your criteria for determining which pixel belongs to what color component?

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#5 Posted : Monday, December 20, 2010 5:55:14 AM(UTC)

RLenski  
RLenski

Groups: Registered
Posts: 12


Maen,

Again thanks for helping me with trying to calculate the pixels. In stepping back, I take 4 1-bit (CMYK) tiff files and merge them into an 8-bit color image using the SaveCMYKArray() function. I then pass this image to another application that needs to calculate the pixels colors used to create that image. For example in a 10 pixel by 10 pixel region, how many of those pixels were used from from the original 4 images to create that color. In that same 10x10 region, how many of those 100 pixels were from the cyan separation originally? The 1-bit tiff file pixels are either white or black used to create the color image. I am trying to track back to cyan, magenta, yellow and black, to calculate how many black pixels in that region there were in each of the separations to create the color. I thought by performing a separation on that same merged cmyk color file, I could separate into the colors and count the number of black pixels of that region? This would give me the percentages I was looking for. Using the 10x10 pixel example, there might be 100% cyan, 20% magenta, 30% yellow, and 70% black, used to make the color of that region. Hopefully that is a little more clear? Thanks again for helping me.

Thanks,
Rich
 
#6 Posted : Tuesday, December 21, 2010 5:28:19 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,328

Was thanked: 1 time(s) in 1 post(s)

Rich,
If the image was saved using SaveCMYKArray(), the only way to get the original CMYK planes is to load them using LoadCMYKArray().
If you use a 'normal' load function, it will convert the image to RGB, and any attempt to convert the data back to CMYK will cause variations from the original CMYK values. These variations can be substantial.
For example (using 256 gray shades, not 1-bit like yours), if you mix the CMYK values (200, 150, 80, 40), you get a slightly dark shade of blue (RGB = 15, 65, 135).
If you separate this RGB color to CMYK using the default LEADTOOLS conversion, you will get CMYK = 120, 70, 0, 120.

Although the original values are completely different from the new CMYK values, the new values also represent the same shade of blue.

In other words, there is no single CMYK set of values that uniquely represents a color. Almost any color can be represented by countless different combinations of CMYK.

Therefore, after a CMYK image is converted to RGB, it's almost impossible to calculate what the original CMYK values were.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#7 Posted : Wednesday, December 22, 2010 5:28:57 AM(UTC)

RLenski  
RLenski

Groups: Registered
Posts: 12


Maen,

Thanks for your help. I believe I understand better on what I can and can't do. I was trying to speed up the processing by passing around a single color image file. Instead I think I am going to have to figure out how to create a multi-page file with the cmyk 1-bit tifs with the combined color image file. If you have any better ideas I would be interested.

Thanks,
Rich
 
#8 Posted : Thursday, December 23, 2010 5:34:25 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,328

Was thanked: 1 time(s) in 1 post(s)

Rich,
You could try the following:
1. Use the GrayScale(8) function to convert the 4 planes (1-bit image) to grayscale.
2. Pass the 4 planes to the SaveCMYKArray() method.
3. The image will be saved as TIFF with proper CMYK format header. However, since the original data was in 1-bit, I'm not sure whether the 8-bit per plane image would look correct or not.
Therefore, you must do your own testing.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
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.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.229 seconds.