Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5970663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:24:26+00:00 2026-05-22T20:24:26+00:00

I wrote an extension method which returns me 2-dimensional array of YUV values from

  • 0

I wrote an extension method which returns me 2-dimensional array of YUV values from a bitmap i.e.:

public static YUV[,] ToYuvLattice(this System.Drawing.Bitmap bm)
{
    var lattice = new YUV[bm.Width, bm.Height];
    for(var ix = 0; ix < bm.Width; ix++)
    {
        for(var iy = 0; iy < bm.Height; iy++)
        {
            lattice[ix, iy] = bm.GetPixel(ix, iy).ToYUV();
        }
    }
    return lattice;
}

Then I need to extract sets with the same U and V components. I.e. Set1 contains all [item1;item2] pairs, Set2 conatains [_item1;_item2] pairs. So I want to get List of Lists.

public IEnumerable<List<Cell<YUV>>> ExtractClusters()
{            
    foreach(var cell in this.lattice)
    {
        if(cell.Feature.U != 0 || cell.Feature.V != 0)
        {
            // other condition to be defined
        }
        // null yet
        yield return null;
    }
} 

I started with above code but I stuck with condition to distinct values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:24:27+00:00Added an answer on May 22, 2026 at 8:24 pm

    It sounds like you have an equivalence relation and you want to partition the data. By equivalence relation, I mean:

    1. A r A
    2. A r B => B r A
    3. A r B and B r C => A r C

    If that is what you have then this should work.

    public static class PartitionExtension
    {
        static IEnumerable<List<T>> Partition<T>(this IEnumerable<T> source, Func<T, T, bool> equivalenceRelation)
        {
            var result = new List<List<T>>();
            foreach (var x in source)
            {
                List<T> partition = result.FirstOrDefault(p => equivalenceRelation(p[0], x));
                if (partition == null)
                {
                    partition = new List<T>();
                    result.Add(partition);
                }
    
                partition.Add(x);
            }
            return result;
        }
    }
    

    Usage:

    return this.lattice
    .Where( c=> c.Feature.U != 0 && c.Feature.V != 0 )
    .Partition((x,y)=>
         x.Feature.U == y.Feature.U &&
         x.Feature.V == y.Feature.V);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to write an extension method for string, which appears as a static
I have an extension method that looks like the following: //[MethodImpl(MethodImplOptions.NoOptimization)] public static IEnumerable<char>
Lets say I have this extention method: public static bool HasFive<T>(this IEnumerable<T> subjects) {
I have the following method: public static TEventInvocatorParameters Until <TEventInvocatorParameters, TEventArgs>(this TEventInvocatorParameters p, Func<TEventArgs,
I was trying to write a simple extension method for Color static class which
I wrote a custom ordering LINQ extension method as below but I think it
I recently found out about C# extension methods and wrote this one: /// <summary>
For a SO question i quite recently wrote a generic extension method that should
I'm wondering if it's possible to write a passthrough extension method for IQueryable which
I have this Class which is accepting a Dictionary<string,object> which is been invoked from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.