Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The function 'getRed' isn't defined. Try importing the library that defines 'getRed', correcting the name to the name of an existing function, or defining a function named #249

Open
itstabrez opened this issue Sep 10, 2024 · 2 comments

Comments

@itstabrez
Copy link

itstabrez commented Sep 10, 2024

 Float32List _imageToByteListFloat32(imglib.Image image) {
 var convertedBytes = Float32List(1 * 112 * 112 * 3);
 var buffer = Float32List.view(convertedBytes.buffer);
 int pixelIndex = 0;
for (var i = 0; i < 112; i++) {
  for (var j = 0; j < 112; j++) {
    var pixel = image.getPixel(j, i);
    buffer[pixelIndex++] = (imglib.getRed(pixel) - 128) / 128;
    buffer[pixelIndex++] = (imglib.getGreen(pixel) - 128) / 128;
    buffer[pixelIndex++] = (imglib.getBlue(pixel) - 128) / 128;
  }
}
return convertedBytes.buffer.asFloat32List();

}

-------------Above is the function to convert image to byte list Float32

Float32List imageAsList = _imageToByteListFloat32(img);

---------------- This is how i am calling the above function..

In the below version of image the code is working well
---image: 3.1.3
but after updating the image version to
---image: ^4.2.0

the imglib.getRed , imglib.getGreen , imglib.getBlue property is not working

how to solve this issue and get the same functionality as above code is serving thanks in advance ...

@itstabrez
Copy link
Author

  Float32List _imageToByteListFloat32(imglib.Image image) {
   var convertedBytes = Float32List(1 * 112 * 112 * 3);
   var buffer = Float32List.view(convertedBytes.buffer);
    int pixelIndex = 0;

for (var i = 0; i < 112; i++) {
  for (var j = 0; j < 112; j++) {
    int pixel = image.getPixel(j, i) as int;
    // Extract RGBA components from pixel value
    int r = (pixel >> 24) & 0xFF;
    int g = (pixel >> 16) & 0xFF;
    int b = (pixel >> 8) & 0xFF;

    // Normalize and store pixel values
    buffer[pixelIndex++] = (r - 128) / 128.0;
    buffer[pixelIndex++] = (g - 128) / 128.0;
    buffer[pixelIndex++] = (b - 128) / 128.0;
  }
}
return convertedBytes.buffer.asFloat32List();

}

solved by replacing the code as above

@PaulTR
Copy link
Collaborator

PaulTR commented Sep 10, 2024

Going to leave this open since it should be tracked to update in a PR. Thanks for bringing it up!

@PaulTR PaulTR reopened this Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants