0

I have an image with nearly smooth background with some extra lines on it. I want to convert the image from RGB color space to LAB color space and then average the "L" part of pixels.

But before converting I want to delete extra lines or somehow ignore lines pixels in averaging the "L" part. Is there any algorithm to do this?

Below is an example of the images I have.

enter image description here

7
  • 1
    What exactly do you want to delete and what exactly do you want to preserve ? (Please don't reply "extra lines".) Commented Oct 12, 2017 at 10:13
  • As you see there is dominant color in the background. Also there are some shapes seen as lines (I mean darker pixels). I have to delete these darker parts. Commented Oct 12, 2017 at 10:15
  • Please make attention that extra lines are not necessarily darker. I want to delete pixels other than dominant color. Commented Oct 12, 2017 at 10:17
  • What will we put in place of the "deleted" pixels? Commented Oct 12, 2017 at 10:24
  • @MarkSetchell nothing ! By deleting I mean not including them in averaging. Commented Oct 12, 2017 at 10:26

3 Answers 3

1

An option is to compute the gradient (Sobel for instance) and avoid doing the accumulation where the gradient magnitude is significant.

Following the comment by @Paul, it will be interesting to see the influence of the threshold level on the computed average.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

I am using ImageMagick like your other question.

This will give you a mask of all the pixels that differ by more than 5% from their surrounding area (it's the 0.05 in the -fx part). It works by loading the stone image, copying it and blurring the copy to remove local details. It then calculates the absolute difference between the original and the blurred copy and sets the pixel to 1 if the difference exceeds 5% else sets it to 0:

convert stone.jpg -colorspace gray \( +clone -blur x10 \) -fx "abs(u-v)>0.05?1:0" mask.png 

enter image description here

Experiment with changing the 0.05 and see what you think.


This will tell you how many pixels in the mask are white. It relies on the mean being sum of pixel brightnesses divided by number of pixels and knowing all pixels are either 0 or 1:

convert mask.png -format "%[fx:int(mean*w*h)]" info: 6155 

This will blacken all the masked pixels. It works by loading both the stone and the mask, inverting the mask and then, at each pixel position, choosing the darker of the two images - so it will choose black everywhere the mask is white and it will choose the stone everywhere else:

convert stone.jpg \( mask.png -negate \) -compose darken -composite nolines.png 

enter image description here

2 Comments

Can you please explain more about the algorithm? I'm going to write the algorithm in opencv.
I can try. Which of the steps are you struggling with? Try adding the OpenCV tag to your question by the way.
0

In ImageMagick, if you make the pixels to be ignored transparent, you can get the average of all non-transparent pixels using -scale 1x1!. For example, from the two images above:

enter image description here

enter image description here

So first put the mask into the alpha channel, then scale the result to one pixel, turn alpha off and get the pixel color:

convert image.jpg mask.png -alpha off -compose copy_opacity -composite -scale 1x1! -alpha off -format "%[pixel:u.p{0,0}]" info: srgb(231,214,198) 

To check, lets make a swatch:

convert -size 100x100 xc:"srgb(231,214,198)" swatch.png 

enter image description here

Or we can recolor the original image:

convert image.jpg -fill "srgb(231,214,198)" -colorize 100 newimage.png 

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.