Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I sort an array of ints in cocoa?
    primarykey
    data
    text
    <p>I'm brand new to programming on the Mac (i.e. xcode and cocoa) and I'm trying to simply perform a bubble sort and am having a lot of difficulty with this. </p> <p>The goal of this is to filter an image using a median filter by using a 9 pixel kernel. I take in the grey scale values of all nine pixels and then I'm trying to put them in a nine point array and sort the array to extract the median value of the nine (so it doesn't matter if I use ascending or descending). </p> <p>I've been trying to store the pixel values (which are ints) into a <code>NSMutableArray</code> but I really have no idea how to go about doing this or how to then sort them when the array is populated.</p> <pre><code> // Perform median filter on all images in the stack for (x = 0; x &lt; [curPix pwidth]; x++){ for (y = 0; y &lt; [curPix pheight]; y++){ float value; int tLeft, tMid, tRight, cLeft, index, cRight, bLeft, bMid, bRight; // takes in pixel placement value = tLeft = tMid = tRight = cLeft = index = cRight = bLeft = bMid = bRight = 0; curPos = y * [curPix pwidth] + x; if (x != 0 &amp;&amp; y != 0 &amp;&amp; x != ([curPix pwidth]-1) &amp;&amp; y != ([curPix pheight]-1)){ //Make kernel for median filter index = fImage[curPos]; // index pixel tLeft = fImage[index - [curPix pwidth] - 1]; // top left tMid = fImage[index - [curPix pwidth]]; // top middle tRight = fImage[index - [curPix pwidth] + 1]; // top right cLeft = fImage[index - 1]; // center left cRight = fImage[index + 1]; // center right bLeft = fImage[index + [curPix pwidth] - 1]; // bottom left bMid = fImage[index + [curPix pwidth]]; // bottom middle bRight = fImage[index + [curPix pwidth] + 1]; // bottom right // Need to make array, populate with pixels (above), and sort. // Once sorted, take median value, save it as 'value', and store it as new pixel value fImage[curPos] = (int) value; // return value to index } else { fImage[curPos] = fImage[curPos]; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload