ImageJ marco Alpha-Beta Contrast Stretching.

喜欢ヅ旅行 2022-04-25 05:38 205阅读 0赞

此代码适用于灰度图

  1. width=getWidth();
  2. height=getHeight();
  3. histo=newArray(256);
  4. for (y=0;y<height;y++){
  5. for(x=0;x<width;x++){
  6. v=getPixel(x,y);
  7. histo[v]++;
  8. }
  9. }
  10. cumu=newArray(256);
  11. temp=0;
  12. for(i=0;i<256;i++){
  13. temp+=histo[i];
  14. cumu[i]=temp;
  15. }
  16. up=width*height*0.9;
  17. down=width*height*0.1;
  18. qup=0;
  19. qdown=0;
  20. for(i=255;i>0;i--)
  21. {
  22. if (cumu[i]<=up)
  23. {qup=i;
  24. break;
  25. }
  26. }
  27. for (i=0;i<256;i++)
  28. {
  29. if (cumu[i]>down){
  30. qdown=i;
  31. break;
  32. }
  33. }
  34. for (y=0;y<height;y++){
  35. for(x=0;x<width;x++){
  36. v=getPixel(x,y);
  37. setPixel(x,y,255/(qup-qdown)*(v-qdown));
  38. }
  39. }

发表评论

表情:
评论列表 (有 0 条评论,205人围观)

还没有评论,来说两句吧...

相关阅读