Can I identify part of an image using something else other than color? For example, If there is an image of a house, I need to extract just the roof from the image, the roof may have different colors, what do I need to do to just extract the roofs from a set of images of houses. Is there anyway I can do it in C#? Even if I have to use pixels and rgb and other image attributes, how can I do it? I have no idea about image processing..

Dani AI

Generated

Treat the job as image segmentation: the goal is a per-pixel mask for "roof" or "hair" rather than a single color or simple blob. Building on the thread replies from and , here are concrete, practical routes you can try from C#.

For small collections or interactive tooling: use region-growing / graph-cut style methods to get a quick mask, refined with superpixels (SLIC) and simple geometric cues (for roofs, look for dominant roof lines with a Hough transform, then refine the polygon). A good starting implementation is OpenCV's GrabCut for interactive foreground extraction (OpenCV GrabCut tutorial). This is fast to try on a few images and helps understand typical failure modes.

For robust, automatic extraction across many photos: use segmentation models. Instance/semantic segmentation models (Mask R-CNN, U-Net variants, or portrait parsers such as BiSeNet) produce accurate masks when trained or fine-tuned. There are face-parsing repositories with pre-trained hair masks you can experiment with (face-parsing.PyTorch) and general instance segmentation implementations like Matterport's Mask R-CNN (Mask R-CNN repo).

C# deployment tip: export a trained model to ONNX and run it from .NET using ONNX Runtime. Minimal inference sketch:

using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;

using var session = new InferenceSession("model.onnx");
var inputName = session.InputMetadata.Keys.First();
var inputTensor = new DenseTensor<float>(new[] {1, 3, height, width});
// fill inputTensor with preprocessed image data
var inputs = new List<NamedOnnxValue> { NamedOnnxValue.CreateFromTensor(inputName, inputTensor) };
using var results = session.Run(inputs);
var output = results.First().AsTensor<float>().ToArray();

Annotation and training: label masks with CVAT or LabelMe, aim for hundreds–thousands of examples for generalization, use augmentation and transfer learning. Measure IoU and inspect per-image failures. Start with a small pipeline, iterate on edge cases, and only scale up to large training when the simpler methods consistently fail.

Recommended Answers

All 7 Replies

Thank yo so much for the reply..
But they are comparing 2 images.. they know what to search for befpore begining.. I only know that I need to search for the roof from an image of a house and extract it.. hav no idea of the color or texture.. Is there someway I could identify the color or texture first and then compare and extract the whole of it from the image??? I know it is complicated but am not able to derive a logic...

I don't know enough about this subject to help much more, but I am fairly certain that if you look more closely at the aforge library you will find somthing that does what you need.

If you think about this from a ground up point of view imagine how hard the proposition is: You need to recognise a roof is a roof ensure it is not somthing similar and extract only the part that is a roof. At the same time bare in mind that a roof can take a huge number of different shapes, textures and colours and be easily confused with any number of other objects.

The best method I can think of for this is probably neural network trained on a large number of roof images.

I hope this is of some help!

thank you so much.. It does sound complicated. If i need to extract hair from an image (face) is there anyway? I mean any attributes or characteristics already defined? I am working on extraction and extracting the hair of a person from an image would also help me with my work.

You're talking about months of work to do this type of image processing properly....... and it is way beyond the scope of any help you can get here. Perhaps if you had specific questions we could help you better.

You can identify some parts of a picture by the contrast of the surrounding pixels. If the roof is black and the house is white you would follow around the black pixels along the edge and it would "select" the roof for you. This is how most photo editors work when you're selecting shapes.

Thanks for the reply, let me be more specific "what do I need to do to extract hair from the image of a person" Is there any predefined textures/color values defining hair? I need to extract the hair from the face

No. By the time you take in to account hair of every color and varying photo quality you are looking at the same thing -- the contrast of pixels around a shape.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.