views:

118

answers:

1

http://www.cc.gatech.edu/classes/AY2000/cs7495_fall/participants/sashag/ps3/getchaincode.m

offset = N/2;       %offset between ajacent pixels

I don't understand what the above mean?

+2  A: 

Chain-code

A chain code is a lossless compression algorithm for monochrome images. The basic principle of chain codes is to separately encode each connected component, or "blot", in the image.

For each such region, a point on the boundary is selected and its coordinates are transmitted.

The encoder then moves along the boundary of the image and, at each step, transmits a symbol representing the direction of this movement. This continues until the encoder returns to the starting position, at which point the blot has been completely described, and encoding continues with the next blot in the image.

Assuming the Black-n-White (binary) Image-array, U are trying to form the chain-code of the image.

Now U can detect the the area of a "BLOT" by checking adjacent pixels for the same value as the current pixel. The two types of adjacency rules are 4 connectivity and 8 connectivity.

The mod function

code(count) = mod( index + offset, N);

returns the "direction" (or displacement) of the next pixel in the blot (relative to the current-pixel).

Hence the N/2 i.e. offset is either 2 or 4 depending on the adjacency U want to impose.

GoodLUCK!!

CVS-2600Hertz
Can you explain what's this line for: `bw = XOR(bw, temp);` ?
Gtker
temp = bwselect(BW,n) displays the image BW on the screen and lets you select the (row,col) coordinates using the mouse. Use normal button clicks to add points. Pressing Backspace or Delete removes the previously selected point. A shift-click, right-click, or double-click selects the final point; pressing Return finishes the selection without adding a point.
CVS-2600Hertz
xor as U know return true whenever there the two operands are different. So i'm assuming, this allows the user to select the points and since these points are the only difference between the array BW and the user array temp. it returns them; effectively allowing the user to perform manual chaincoding.
CVS-2600Hertz
If U look carefully, this part of the code executes only if the script detects an occluded image and hence in unable to continue. i.e. something like "fall-back" to user-mode from auto-mode. ( rather than exiting with an error)
CVS-2600Hertz
Can you answer what exactly does the final 5 lines do?
Gtker
ok.(AFAIU) Here's what the final 5 lines do. [1] These are executed only if the perimeter length obtained in less than 32 nodes OR if the algorithm detects an occluded image. [2] bwselect pops-up the image and waits for the user to click on the image and select points (as described in my prev comment) [3] xor operation done on the new image(temp) and the original image(bw). Pixels that are different between the two imgs become 1, rest all pixes 0. [4] This new difference image (obtained from xor) is now passed to a new-instance of the same function to find the chaincode.
CVS-2600Hertz
Do i get a TICK for the answer ;-)
CVS-2600Hertz
`temp = bwselect(bw, current(2), current(1), N);` I don't think this statement will ** pops-up the image and waits for the user to click on the image **
Gtker
Sorry my fault then. temp = bwselect(bw, current(2), current(1), N) would return a binary image containing the objects that overlap the pixel (r,c). r and c can be scalars or equal-length vectors. i.e. U get a "sub-image" of sorts...
CVS-2600Hertz
this is because U are already specifying the co-ordinates current(2), current(1) and hence using this, bwselect, returns the sub image... checkout Matlab's Online-Documentation for bwSelect here http://www.mathworks.com/access/helpdesk/help/toolbox/images/bwselect.html
CVS-2600Hertz
Yes,but I don't see what will `bw` be like after `bw = XOR(bw, temp);`
Gtker
ok let me try explaining that now: U see, the xor function returns 1 when its two operands are different, and 0 when both operands are same. so when we xor the sub-image w.r.t the original image, the pixels of the sub-image will be same i.e. xor will return 0. This ought to mean that the area of the occluded image is "blackened-out" (same means xor returns 0 i.e. BLACK) I hope i'm right. Did U try it out? what output did U get??...
CVS-2600Hertz
Is the `occluded image` an un-closed curve?
Gtker
http://journalofvision.org/9/4/4/images/fig01.gif Occlusion of the face by RED-pixels is increasing from left to right. I hope U get the PICTURE now. (pun-intended) ;-)
CVS-2600Hertz
But why `if ( current(1)<2 | current(2)<2 ) | ( current(1) == height | current(2) == width )` can be used to determin an occluded image?
Gtker
Well, i too am a bit gray there... :( The code tries to find the first non-empty (non-zero) pixel and then continue to find the directions to the next adjacent pixel from there onwards. In case the current pixel lies to the left-top of (2,2) or is the bottom-right pixel then its assumed to be an occluded-image (see the code-warning).
CVS-2600Hertz
Ok,that's not so important,but this line is fatal(I don't understand) : `index = mod( code(count) + 1, N ); %index will equal current chaincode + 1` ,why should *index equal current chaincode + 1*?
Gtker
I'm guessing you don not understand the chaincode algorithm itself OR maybe this particular implementation in matlab. Try this: http://www.miszalok.de/Samples/CV/ChainCode/chaincode_kovalev_e.htm This should help you with all your doubts regarding the chaincode algorithm.
CVS-2600Hertz
It seems the link you give calculates **all** separate bundary component's chain code,but the one I posted calculates only **one** of the bundary component,is that right?
Gtker
Hello,can you confirm my last short question?
Gtker
That's how chaincode-encoding works. U encode each block separately as "chain of codes" along the boundary. Once the whole boundary is traversed, that "blot" is done and removed and next "blot" is scanned for and encoded. This is done iteratively, until no more blots remain!!
CVS-2600Hertz