storing image information in a 2-d array

2 views (last 30 days)
hello everyone... my problem is i want to divide an color image into 100 blocks of equal size and then store the maximum color information present in the box in a 2d array of 10*10..for instance if the maximum color present in the block is black,it should store 0 in the corresponding cell of 2d array,if white then 1,if red then 2 and so on...i have finite number of colors in my image...i read an article on blockproc but i was unable to implement it...may i have some help or suggestions plz.... thnx in advance...any help is highly appreciated..:)
  2 Comments
Walter Roberson
Walter Roberson on 28 Dec 2011
RGB images? Or pseudocolor but the color indices do not match your target numbers? Or pseudocolors and the color indices do already match your target numbers?
geekotronics
geekotronics on 29 Dec 2011
yeah it would be rgb images....i would be setting the target numbers as per my need...i guess this can be done using a simple if-else condition...

Sign in to comment.

Accepted Answer

Chandra Kurniawan
Chandra Kurniawan on 28 Dec 2011
Hello,
That's true. You can use blockproc from Matlab.
It's simple to use.
B = blockproc(A,[M N],fun)
A is input image, [M N] is size of block, and fun is function handle
If you want to divide image into 100 equal block, then
you can divide image width and height by 10. This is for size of the block.
Here my sample code :
I = imread('peppers.png');
I = I(1:300,1:500,:);
[m n o] = size(I);
r = m/10;
c = n/10;
fun = @(block_struct) max(block_struct.data(:));
J = blockproc(I,[r c],fun)
J will returns 10x10 array that represent maximum value of each corresponding block.
J =
75 78 77 84 84 82 80 87 82 73
77 83 79 82 83 83 84 135 81 75
77 83 84 90 254 174 157 250 119 74
82 150 215 207 255 255 212 249 194 165
77 136 247 191 225 239 170 255 255 255
76 169 190 255 255 255 255 255 255 251
255 255 245 255 255 255 255 255 250 233
255 255 255 255 255 255 255 216 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 254 202 197 173 177 255 255
I hope this will helps you.
  3 Comments
Walter Roberson
Walter Roberson on 29 Dec 2011
The line
fun = @(block_struct) max(block_struct.data(:));
defines fun right there, so it was not pre-defined.
geekotronics
geekotronics on 29 Dec 2011
yeah it was...but i didnt mean the same....i meant that instead of max(block_struct.data(:)) ;,can i define it in some other way....like i thought of assigning 2 if the color is red,1 if it is white ,3 if it is blue and so on....i will be losing the color if i use max(block_struct.data(:))....

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!