AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Algorithmen, Datenstrukturen und Klassendesign Problem mit verschiedenen Typen im RGB-to-HSL-Range Procedur
Thema durchsuchen
Ansicht
Themen-Optionen

Problem mit verschiedenen Typen im RGB-to-HSL-Range Procedur

Ein Thema von neumimnemecky · begonnen am 4. Jul 2022 · letzter Beitrag vom 5. Jul 2022
Antwort Antwort
neumimnemecky

Registriert seit: 21. Dez 2018
45 Beiträge
 
#1

Problem mit verschiedenen Typen im RGB-to-HSL-Range Procedur

  Alt 4. Jul 2022, 16:25
Guten tag,
can you help with this procedure derived from Color Lib v2.0.2? In original code in module RGBHSLUtils, there is similar procedure RGBtoHSLRange(RGB: TColor; var H1, S1, L1 : integer); using TColor as input parameter. Hence I wanted to create modified function in RGBHSVUtils for convertion to HSV. The HSV original procedure is RGB2HSV(R, G, B: integer; var H: Word; var S, V: byte); // passing Integer inputs(!). So I decided to pass TColor, but here is the problem. How to make it working now? There is the error : RGBHSVUtils.pas(232*): Incompatible types: 'Byte' and 'Extended'; *note: modified version is on my PC.

Verfahren abgeleitet von Color Lib v2.0.2.

Code:
procedure RGB2HSVRange(RGB: TColor; var H: Word;var S,V: byte);
var
 Delta, Min, H1, S1: real;
 R, G, B: byte;
begin
 R := GetRValue (RGB) / 255;
 G := GetGValue (RGB) / 255;
 B := GetBValue (RGB) / 255;
 h1 := h;
 s1 := s;
 // Min := MinIntValue([R, G, B]);
 Min := R;
 if Min > G then
   Min := G;
 if Min > B then
   Min := B;
 // V := MaxIntValue([R, G, B]);
 V := R;
 if V < G then
   V := G;
 if V < B then
   V := B;
 Delta := V - Min;
 if V = 0.0 then S1 := 0 else S1 := Delta / V;
 if S1  = 0.0 then
  H1 := 0
 else
  begin
   if R = V then
    H1 := 60.0 * (G - B) / Delta
   else
    if G = V then
     H1 := 120.0 + 60.0 * (B - R) / Delta
    else
     if B = V then
      H1 := 240.0 + 60.0 * (R - G) / Delta;
   if H1 < 0.0 then H1 := H1 + 360.0;
  end;
 h := round(h1);
 s := round(s1*255);
end;

Geändert von neumimnemecky ( 4. Jul 2022 um 17:13 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.139 Beiträge
 
Delphi 12 Athens
 
#2

AW: Problem mit verschiedenen Typen im RGB-to-HSL-Range Procedur

  Alt 4. Jul 2022, 22:29
Code:
 R := GetRValue (RGB) / 255;
 G := GetGValue (RGB) / 255;
 B := GetBValue (RGB) / 255;

^^^ Byte  :=         ^^^ Float
Doesn't the compiler tell you exactly what's wrong?

On the right you have a float (Extended) and you want to assign that to an integer (byte) on the left, which of course cannot work.
Why are you dividing there at all?



Also, the compiler should tell you that these lines are wrong (useless).
Delphi-Quellcode:
 h1 := h;
 s1 := s;
If you change a little thing, you will quickly realize that the value is only output, but not input (InOut).
Delphi-Quellcode:
//procedure RGB2HSVRange(RGB: TColor; var H: Word; var S, V: Byte);
  procedure RGB2HSVRange(RGB: TColor; out H: Word; out S, V: Byte);
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu ( 4. Jul 2022 um 23:21 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: Problem mit verschiedenen Typen im RGB-to-HSL-Range Procedur

  Alt 5. Jul 2022, 05:20
Why not use RGBtoHSL from Delphi? What is wrong with it?
rgb - > hsv and hsv -> rgb
Gruß vom KodeZwerg

Geändert von KodeZwerg ( 5. Jul 2022 um 05:30 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Sinspin
Sinspin

Registriert seit: 15. Sep 2008
Ort: Dubai
615 Beiträge
 
Delphi 10.3 Rio
 
#4

AW: Problem mit verschiedenen Typen im RGB-to-HSL-Range Procedur

  Alt 5. Jul 2022, 07:16
I had a few month ago the same thoughts in my mind, why not using this implementation or why not that.
Result is, i use now a version which is as close as possible to the original, since i need to convert both way.

The Single/Float values are confusing at the beginning. But they have an nice advantage, you get much smoother values than you would get with integer!
So, you should keep Single values, if you need to display them, you need to quantize the values.
For example for S with 100, for percent style Saturation. Or at least 360 for the color angle H-Hue, but 360 is by far not enough values for perfect color representation!
Stefan
Nur die Besten sterben jung
A constant is a constant until it change.
  Mit Zitat antworten Zitat
neumimnemecky

Registriert seit: 21. Dez 2018
45 Beiträge
 
#5

AW: Problem mit verschiedenen Typen im RGB-to-HSL-Range Procedur

  Alt 5. Jul 2022, 07:58
Thank you to all for replies. I am new to graphics topics, and I am on the very beginning. It is just my exploration. I am working on a program which should be able to locate text in image and possibly some easy objects like arrows/images. The program should work with images exported from video or GIF and try to correct some frames. As it is supposed there is just text or mostly the text alone and it is well visible to be recognizable, but I will detect only for such easy characters like T, I, J etc. Then I will move the images or parts of the images (copy from one image to another). So I will not do any image conversion. Now I prepare input params for the program, and the elements to be found are defined by H, S, L (or H, S, V) values + some tolerance or fuzzyness. In the image exported from AVI in very good quality, there is very good quality, but a small tolerance for hue needed.

I am not expert in math or programming, I just need to make program to correct some graphics in video captured during scrolling a website.

Geändert von neumimnemecky ( 5. Jul 2022 um 08:01 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:51 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz