Click here to Skip to main content
15,868,123 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I got a tool from elsewhere

It can list the pixel values used by the image

i try to imitate it

I use the memory method to extract image pixel colors values and remove duplicate values, but I can't achieve its sorting effect.

Pixel Sort Sample Image URL:https://drive.google.com/file/d/1EdY_JPmU_wfUFuw2202Yq64ocInLabUR/view?usp=share_link

Arranged from top to bottom (5 pictures result)

What I have tried:

C#
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            int stride = bitmapData.Stride; 
            IntPtr iptr = bitmapData.Scan0;  
            int DataBytes = stride * bitmap.Height;  
            byte[] Data = new byte[DataBytes];
            Marshal.Copy(iptr, Data, 0, DataBytes);
            bitmap.UnlockBits(bitmapData);
Posted
Updated 23-Jul-23 20:57pm
v3
Comments
Richard MacCutchan 22-Nov-22 10:21am    
Please use the Improve question link above, and add complete details of what is not working.
[no name] 22-Nov-22 13:08pm    
There is no intuitive way to simply sort RGB values (that I found; it's a function of their interaction). You create a table of "colors" you want to recognize and assign a sequence number (meaning) that suits your needs. I use a "color table" to create and interpret map elevations.

1 solution

You could convert from RGB to HSV/HSB and use the (H)ue to create your color groups, then (S)aturation & (B)rightness to do your sub-sorts. Then once sorted, display the RGB value.

ref: The HSB Color System: A Practitioner's Primer – Learn UI Design[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900