I switched the two lines, value is 1, here is the immediate result:

edges are a bit not precise since it relies on work path:

So I used Select > Grow Like you told me on your first reply + Expand 4px,
It's not perfect because it's via paths but it's good enough, i will try on many more pictures and share them 
Thank you
The value you switched to is too low as process will take too long time. Use at least value 2 or higher like I suggested so it's going to work very fast. I was aware of edges they will be rounded, and adviced to add part of code that fix that (however I guess you could do it manually).
You must specify the value of Magic Wand if you use 'Select / Grow'. I'm not sure why you then use Expand +4, but if you added additional step that selecting black pixels again you had perfect selection of your carpet. Anyway here is complete code for that:
sTT = stringIDToTypeID, dsc = new ActionDescriptor()
function cR() {
dsc.putEnumerated(c = sTT('colors'), c, sTT('shadows')), executeAction(sTT('colorRange'), dsc)
}
cR(), dsc.putInteger(sTT('shadowsUpperLimit'), 0), dsc.putBoolean(sTT('invert'), false)
ref1 = new ActionReference(), ref2 = new ActionReference(), ref1.putClass(sTT('path'))
dsc.putReference(sTT('null'), ref1), ref2.putProperty(sTT('selectionClass'), sTT('selection'))
dsc.putReference(sTT('from'), ref2), dsc.putUnitDouble(sTT('tolerance'), sTT('pixelsUnit'), 2)
executeAction(sTT('make'), dsc)
len = (sPI = (pI0 = (aD = activeDocument).pathItems[0]).subPathItems).length
for(arr = [], i = 0; i < len; i++) {
for(pts = [], j = 0; j < (pP = sPI.pathPoints).length;) pts.push(pP[j++].anchor);
(sel = aD.selection).select(pts), hst = aD.histogram[0]
$.level = 0; try{
sel.bounds; if (!arr.length || hst > arr[0][0]) arr[0] = [hst, pts, i]
}
catch(err){}
}
pI0.remove(), sel.select(arr[0][1]), sel.grow(255, true), sel.expand(5), cR()
In the last line instead of sel.grow(255, true), sel.expand(5), cR() you can use sel.contract(5), sel.grow(255, true) so it's going to select all little white pixels inside of main subject also to avoid selection of little dark pixels outside of carpet.
And yes share more pictures, I wonder how that will work on rest of them 
Ah, and the procedure is accordingly to that you provided:
- there still must be 3 layers (Threshold set to 255, middle main layer and Color Fill - white - layer)
- you make active middle layer, use Magic Wand on White area (with tolerance of 10)
- after you remove and deselect selected white area you run script (value 2)