필터 지우기
필터 지우기

Recolor an image tile-wise with average colors of these certain tiles

조회 수: 3 (최근 30일)
Hello everyone,
I have the following image (original image is .tif format)
Now, I would like to recolor it, that I don't have single color pixels anymore. I imagine something like the following:
assess a 10 x 10 pixel wide tile (or any other size), add only the non-zero color values and devide it by the number of non-zero values in this 10 x 10 tile to get the average pixel color. Than, recolor this 10 x 10 tile with the average pixel color. And than repeat this, with all possible not overlapping tiles of the image.
I hope, someone is 1. abler to understand waht I tried to say and 2. also able to help me.
Thank you!
Julian

채택된 답변

Sean de Wolski
Sean de Wolski 2013년 5월 23일
Use blockproc to handle the block processing
doc blockproc
Then write a function which does the average ignoring zeros. So something like:
blockproc(magic(100),[10 10], @(bs)(sum(bs.data(logical(bs.data)))./nnz(bs.data))*ones(size(bs.data)))
  댓글 수: 3
Sean de Wolski
Sean de Wolski 2013년 5월 23일
편집: Sean de Wolski 2013년 5월 24일
You could use it in a for-loop over each colorplane
szI = size(I);
I2 = zeros(szI,'like',I);
for ii = 1:szI(3)
I2(:,:,ii) = what_I_Have(I(:,:,ii));
end
Julian
Julian 2013년 5월 24일
Great! It's always amazing, how fast someone is able to help around here :)
Thank you again!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2013년 5월 23일
편집: Matt J 2013년 5월 23일
Splitting the image into tiles is easy using FEX: mat2tiles.
>> Image=rand(40,40); mat2tiles(Image,[10,10])
ans =
[10x10 double] [10x10 double] [10x10 double] [10x10 double]
[10x10 double] [10x10 double] [10x10 double] [10x10 double]
[10x10 double] [10x10 double] [10x10 double] [10x10 double]
[10x10 double] [10x10 double] [10x10 double] [10x10 double]
You can then do all the operations you're talking about on each cell using a simple for-loop.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by