embedDataInBlock[block, dataBit, mask, inverseMask, luminanceCoefficients, alpha] :=…
- User
embedDataInBlock[block_, dataBit_, mask_, inverseMask_, luminanceCoefficients_, alpha_] := Module[{blockData, flattenB1, flattenB0, lumB1, lumB0, deltaLum, deltaB, deltaArray}, blockData = ImageData[block, "Byte"]; flattenB1 = Flatten[blockDatamask, 1]; flattenB0 = Flatten[blockDatainverseMask, 1]; lumB1 = Mean[Dot[flattenB1, luminanceCoefficients]]; lumB0 = Mean[Dot[flattenB0, luminanceCoefficients]]; deltaLum = 0; If[dataBit == 1 && lumB0 - lumB1 <= alpha, deltaLum = alpha + 1 - (lumB0 - lumB1); deltaB = deltaLum*luminanceCoefficients; deltaArray = ConstantArray[deltaB, {8, 8}]inverseMask; blockData += deltaArray;]; If[dataBit == 0 && lumB0 - lumB1 >= -alpha, deltaLum = -alpha - 1 - (lumB0 - lumB1); deltaB = deltaLumluminanceCoefficients; deltaArray = ConstantArray[deltaB, {8, 8}]*inverseMask; blockData += deltaArray;]; (Print["Яркость с маской 1: ",lumB1,", Яркость с маской 0: ", lumB0,", Разница в яркости (deltaLum): ",deltaLum, ", Встраиваемый бит: ",dataBit]) Image[Clip[Round[blockData], {0, 255}], "Byte"]]; stegoBlocks = blocks; Do[If[cvzIndex <= cvzLength, stegoBlocks[[i, j]] = embedDataInBlock[stegoBlocks[[i, j]], CVZ[[cvzIndex]], mask, inverseMask, luminanceCoefficients, alpha]; cvzIndex++;], {j, Length[stegoBlocks[[1]]]}, {i, Length[stegoBlocks]}]; stegoImage1 = ImageAssemble[stegoBlocks]; исправь стего путь на Последовательно, непрерывно, по строкам.
- Assistant
It seems like you want to adjust the iteration order in the loop such that the blocks are processed sequentially across rows. Your current
Doloop structure has nested loops first going over the first index (i), then the second index (j). This processes the blocks column by column rather than row by row.Here's how to adjust the
Doloop to process the blocks row by row:stegoBlocks = blocks; Do[ If[cvzIndex <= cvzLength, stegoBlocks[[i, j]] = embedDataInBlock[ stegoBlocks[[i, j]], CVZ[[cvzIndex]], mask, inverseMask, luminanceCoefficients, alpha ]; cvzIndex++; ], {i, Length[stegoBlocks]}, (* Iterate over rows *) {j, Length[stegoBlocks[[i]]]} (* Iterate over columns within each row *) ]; stegoImage1 = ImageAssemble[stegoBlocks];In this corrected code, the order of the indices in the
Doloop has been switched so that the outer loop goes overi(rows) and the inner loop goes overj(columns). This means that the blocks will be processed in a left-to-right, top-to-bottom order, which is typical for image processing when you want to process blocks sequentially across rows.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.